forked from SimonRichards/clang-sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Type.cs
192 lines (172 loc) · 5.4 KB
/
Type.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
namespace ClangSharp {
public class Type {
internal Interop.Type Native { get; private set; }
internal Type(Interop.Type native) {
Native = native;
}
public Type ArrayElementType
{
get { return new Type(Interop.clang_getArrayElementType(Native)); }
}
public Type Canonical {
get { return new Type(Interop.clang_getCanonicalType(Native)); }
}
public Type Pointee {
get { return new Type(Interop.clang_getPointeeType(Native)); }
}
public Type Result {
get { return new Type(Interop.clang_getResultType(Native)); }
}
public Cursor Declaration {
get { return new Cursor(Interop.clang_getTypeDeclaration(Native)); }
}
public Kind TypeKind {
get { return Native.kind; }
}
public string TypeKindSpelling {
get {
return Interop.clang_getTypeKindSpelling(TypeKind).ManagedString;
}
}
public bool IsConstQualifiedType
{
get { return Interop.clang_isConstQualifiedType(Native) != 0; }
}
public bool IsRestrictQualifiedType
{
get { return Interop.clang_isRestrictQualifiedType(Native) != 0; }
}
public bool IsVolatileQualifiedType
{
get { return Interop.clang_isVolatileQualifiedType(Native) != 0; }
}
public bool IsFunctionTypeVariadic
{
get { return Interop.clang_isFunctionTypeVariadic(Native) != 0; }
}
public int NumArgTypes
{
get { return Interop.clang_getNumArgTypes(Native); }
}
public Type GetArgType(uint i)
{
return new Type(Interop.clang_getArgType(Native, i));
}
public bool Equals(Type other) {
return Interop.clang_equalTypes(Native, other.Native) != 0;
}
public override bool Equals(object obj) {
return obj is Type && Equals((Type)obj);
}
public override int GetHashCode() {
return Native.GetHashCode();
}
public enum Kind {
Invalid,
Unexposed,
Void,
Bool,
CharU,
UChar,
Char16,
Char32,
UShort,
UInt,
ULong,
ULongLong,
UInt128,
CharS,
SChar,
WChar,
Short,
Int,
Long,
LongLong,
Int128,
Float,
Double,
LongDouble,
NullPtr,
Overload,
Dependent,
ObjCId,
ObjCClass,
ObjCSel,
FirstBuiltin = 2,
LastBuiltin = 29,
Complex = 100,
Pointer,
BlockPointer,
LValueReference,
RValueReference,
Record,
Enum,
Typedef,
ObjCInterface,
ObjCObjectPointer,
FunctionNoProto,
FunctionProto,
ConstantArray,
Vector,
IncompleteArray,
VariableArray,
DependentSizedArray,
MemberPointer
}
public string Spelling {
get {
switch (TypeKind) {
case Kind.Void:
return "void";
case Kind.Bool:
return "bool";
case Kind.UChar:
case Kind.CharU:
return "unsigned char";
case Kind.Char16:
return "char16_t";
case Kind.Char32:
return "char32_t";
case Kind.UShort:
return "unsigned short int";
case Kind.UInt:
return "unsigned int";
case Kind.ULong:
return "unsigned long int";
case Kind.ULongLong:
return "unsigned long long int";
case Kind.UInt128:
return "uint128_t";
case Kind.CharS:
return "char";
case Kind.SChar:
return "signed char";
case Kind.WChar:
return "wchar_t";
case Kind.Short:
return "short int";
case Kind.Int:
return "int";
case Kind.Long:
return "long int";
case Kind.LongLong:
return "long long int";
case Kind.Int128:
return "int128_t";
case Kind.Float:
return "float";
case Kind.Double:
return "double";
case Kind.LongDouble:
return "long double";
case Kind.NullPtr:
return "nullptr";
case Kind.Pointer:
return Pointee.Spelling + "*";
default:
return Declaration.Spelling;
}
}
}
}
}