-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathCppElement.cs
77 lines (66 loc) · 2.39 KB
/
CppElement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.
using System;
using System.Runtime.CompilerServices;
namespace CppAst
{
/// <summary>
/// Base class for all Cpp elements of the AST nodes.
/// </summary>
public abstract class CppElement : ICppElement
{
/// <summary>
/// Gets or sets the source span of this element.
/// </summary>
public CppSourceSpan Span;
/// <summary>
/// Gets or sets the parent container of this element. Might be null.
/// </summary>
public ICppContainer Parent { get; internal set; }
public sealed override bool Equals(object obj) => ReferenceEquals(this, obj);
public sealed override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
public string FullParentName
{
get
{
string tmpname = "";
var p = Parent;
while (p != null)
{
if (p is CppClass)
{
var cpp = p as CppClass;
tmpname = $"{cpp.Name}::{tmpname}";
p = cpp.Parent;
}
else if (p is CppNamespace)
{
var ns = p as CppNamespace;
//Just ignore inline namespace
if (!ns.IsInlineNamespace)
{
tmpname = $"{ns.Name}::{tmpname}";
}
p = ns.Parent;
}
else
{
// root namespace here, or no known parent, just ignore~
p = null;
}
}
//Try to remove not need `::` in string tails.
if (tmpname.EndsWith("::"))
{
tmpname = tmpname.Substring(0, tmpname.Length - 2);
}
return tmpname;
}
}
/// <summary>
/// Gets the source file of this element.
/// </summary>
public string SourceFile => string.IsNullOrWhiteSpace(Span.Start.File) ? (Parent as CppElement)?.SourceFile : Span.Start.File;
}
}