Skip to content

Commit 072f43c

Browse files
committed
chore: generate symbol IDs for type by looking through pointers/references etc
1 parent 75cd2dd commit 072f43c

File tree

9 files changed

+420
-26
lines changed

9 files changed

+420
-26
lines changed

source/AST/ASTVisitor.cpp

Lines changed: 128 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,139 @@ getCXXRecordDeclForType(
168168
return nullptr;
169169
}
170170

171-
TypeInfo
171+
SymbolID
172172
ASTVisitor::
173-
getTypeInfoForType(
173+
getSymbolIDForType(
174174
QualType T)
175175
{
176176
SymbolID id = SymbolID::zero;
177-
if(const TagDecl* TD = getTagDeclForType(T))
177+
QualType inner = T;
178+
while(true)
178179
{
179-
extractSymbolID(TD, id);
180-
return TypeInfo(id, TD->getNameAsString());
180+
inner = inner.getLocalUnqualifiedType();
181+
const Type* type = inner.getTypePtr();
182+
switch(inner->getTypeClass())
183+
{
184+
// parenthesized types
185+
case Type::Paren:
186+
{
187+
auto* PT = cast<ParenType>(type);
188+
inner = PT->getInnerType();
189+
continue;
190+
}
191+
// pointers
192+
case Type::Pointer:
193+
{
194+
auto* PT = cast<PointerType>(type);
195+
inner = PT->getPointeeType();
196+
continue;
197+
}
198+
// references
199+
case Type::LValueReference:
200+
case Type::RValueReference:
201+
{
202+
auto* RT = cast<ReferenceType>(type);
203+
inner = RT->getPointeeType();
204+
continue;
205+
}
206+
// pointer to members
207+
case Type::MemberPointer:
208+
{
209+
auto* MPT = cast<MemberPointerType>(type);
210+
inner = MPT->getPointeeType();
211+
continue;
212+
}
213+
// arrays
214+
case Type::ConstantArray:
215+
case Type::IncompleteArray:
216+
case Type::VariableArray:
217+
case Type::DependentSizedArray:
218+
{
219+
auto* AT = cast<ArrayType>(type);
220+
inner = AT->getElementType();
221+
continue;
222+
}
223+
// elaborated type specifier
224+
case Type::Elaborated:
225+
{
226+
auto* ET = cast<ElaboratedType>(type);
227+
inner = ET->getNamedType();
228+
continue;
229+
}
230+
// type with __atribute__
231+
case Type::Attributed:
232+
{
233+
auto* AT = cast<AttributedType>(type);
234+
inner = AT->getModifiedType();
235+
continue;
236+
}
237+
// adjusted and decayed types
238+
case Type::Decayed:
239+
case Type::Adjusted:
240+
{
241+
auto* AT = cast<AdjustedType>(type);
242+
inner = AT->getOriginalType();
243+
continue;
244+
}
245+
// using declarations
246+
case Type::Using:
247+
{
248+
auto* UT = cast<UsingType>(type);
249+
// look through the using declaration and
250+
// use the the type from the referenced declaration
251+
inner = UT->getUnderlyingType();
252+
continue;
253+
}
254+
// specialization of a class/alias template or
255+
// template template parameter
256+
case Type::TemplateSpecialization:
257+
{
258+
auto* TST = cast<TemplateSpecializationType>(type);
259+
// use the SymbolID of the corresponding template if it is known
260+
if(auto* TD = TST->getTemplateName().getAsTemplateDecl())
261+
return extractSymbolID(TD);
262+
return SymbolID::zero;
263+
}
264+
// pack expansion
265+
case Type::PackExpansion:
266+
{
267+
auto* PET = cast<PackExpansionType>(type);
268+
inner = PET->getPattern();
269+
continue;
270+
}
271+
// record type
272+
case Type::Record:
273+
{
274+
auto* RT = cast<RecordType>(type);
275+
return extractSymbolID(RT->getDecl());
276+
}
277+
// enum type
278+
case Type::Enum:
279+
{
280+
auto* ET = cast<EnumType>(type);
281+
return extractSymbolID(ET->getDecl());
282+
}
283+
// typedef/alias type
284+
case Type::Typedef:
285+
{
286+
auto* TT = cast<TypedefType>(type);
287+
return extractSymbolID(TT->getDecl());
288+
}
289+
default:
290+
return SymbolID::zero;
291+
}
181292
}
182-
return TypeInfo(id, getTypeAsString(T));
293+
294+
}
295+
296+
TypeInfo
297+
ASTVisitor::
298+
getTypeInfoForType(
299+
QualType T)
300+
{
301+
return TypeInfo(
302+
getSymbolIDForType(T),
303+
getTypeAsString(T));
183304
}
184305

185306
void
@@ -190,11 +311,8 @@ parseParameters(
190311
{
191312
for(const ParmVarDecl* P : D->parameters())
192313
{
193-
// KRYSTIAN NOTE: call getOriginalType instead
194-
// of getType if we want to preserve top-level
195-
// cv-qualfiers/array types/function types
196314
I.Params.emplace_back(
197-
getTypeInfoForType(P->getType()),
315+
getTypeInfoForType(P->getOriginalType()),
198316
P->getNameAsString(),
199317
getSourceCode(D, P->getDefaultArgRange()));
200318
}

source/AST/ASTVisitor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class ASTVisitor
111111
getCXXRecordDeclForType(
112112
QualType T);
113113

114+
SymbolID
115+
getSymbolIDForType(
116+
QualType T);
117+
114118
TypeInfo
115119
getTypeInfoForType(
116120
QualType T);

test-files/old-tests/alias-template.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<tparam name="T" class="type"/>
2020
<alias name="C" id="f75RIL8qKOwbyH6ffvrv59F0nCA=">
2121
<file path="alias-template.cpp" line="8" class="def"/>
22-
<type name="A&lt;T&gt;"/>
22+
<type name="A&lt;T&gt;" id="5tUSuMtQqtYE49jBjSYSWp0DJAM="/>
2323
</alias>
2424
</template>
2525
<template>
@@ -30,7 +30,7 @@
3030
<tparam name="U" class="type"/>
3131
<alias name="E" id="STM3CgeaOEakPrQJdlRWWM4MMFo=">
3232
<file path="alias-template.cpp" line="14" class="def"/>
33-
<type name="B&lt;T, U&gt;"/>
33+
<type name="B&lt;T, U&gt;" id="swBEqeWAJoaWVKty+1lCoYUK04A="/>
3434
</alias>
3535
</template>
3636
</struct>

test-files/old-tests/explicit-ctor.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
<function name="Explicit" id="CuzDbFSxtCdVcGerq2UySnHF7po=">
1212
<file path="explicit-ctor.cpp" line="5"/>
1313
<attr id="explicit-spec" name="explicit" value="1"/>
14-
<param type="const Explicit &amp;"/>
14+
<param type="const Explicit &amp;" id="bonobNKGOblPVcRjxpiPan4nYnc="/>
1515
</function>
1616
<function name="Explicit" id="saOH3agrCzNHcRhbXHOM0FYFxGc=">
1717
<file path="explicit-ctor.cpp" line="6"/>
1818
<attr id="exception-spec" name="noexcept" value="5"/>
1919
<attr id="explicit-spec" name="explicit" value="1"/>
20-
<param type="Explicit &amp;&amp;"/>
20+
<param type="Explicit &amp;&amp;" id="bonobNKGOblPVcRjxpiPan4nYnc="/>
2121
</function>
2222
<function name="Explicit" id="Oj6cGCOaarVfZXkgsr/pOPOOiFY=">
2323
<file path="explicit-ctor.cpp" line="7"/>
@@ -35,13 +35,13 @@
3535
<function name="ExplicitTrue" id="Tj9uY+jY7QBYQC8IsjplHuoDgQo=">
3636
<file path="explicit-ctor.cpp" line="12"/>
3737
<attr id="explicit-spec" name="explicit(true)" value="3"/>
38-
<param type="const ExplicitTrue &amp;"/>
38+
<param type="const ExplicitTrue &amp;" id="htdCGapMsdazR1XkXoanrOCkvDE="/>
3939
</function>
4040
<function name="ExplicitTrue" id="iQOO8pEh0iNSnpupVwR9tCVIf8U=">
4141
<file path="explicit-ctor.cpp" line="13"/>
4242
<attr id="exception-spec" name="noexcept" value="5"/>
4343
<attr id="explicit-spec" name="explicit(true)" value="3"/>
44-
<param type="ExplicitTrue &amp;&amp;"/>
44+
<param type="ExplicitTrue &amp;&amp;" id="htdCGapMsdazR1XkXoanrOCkvDE="/>
4545
</function>
4646
<function name="ExplicitTrue" id="XCoHYDLlYJYpV6Ut7Ms0GjcQKjM=">
4747
<file path="explicit-ctor.cpp" line="14"/>
@@ -59,13 +59,13 @@
5959
<function name="ExplicitFalse" id="gsl+2i8v8v4Lifq3SZ5sFhSfseQ=">
6060
<file path="explicit-ctor.cpp" line="19"/>
6161
<attr id="explicit-spec" name="explicit(false)" value="2"/>
62-
<param type="const ExplicitFalse &amp;"/>
62+
<param type="const ExplicitFalse &amp;" id="Lt5u3k14Z7EBxY7Ike3h9qkJ0fo="/>
6363
</function>
6464
<function name="ExplicitFalse" id="qXjKOO0FQ3p2vTehkEQl2kIKpFs=">
6565
<file path="explicit-ctor.cpp" line="20"/>
6666
<attr id="exception-spec" name="noexcept" value="5"/>
6767
<attr id="explicit-spec" name="explicit(false)" value="2"/>
68-
<param type="ExplicitFalse &amp;&amp;"/>
68+
<param type="ExplicitFalse &amp;&amp;" id="Lt5u3k14Z7EBxY7Ike3h9qkJ0fo="/>
6969
</function>
7070
<function name="ExplicitFalse" id="T0aRgSzz7xtFbPWKv3q57ueIYlI=">
7171
<file path="explicit-ctor.cpp" line="21"/>

test-files/old-tests/explicit-deduct-guide.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
<file path="explicit-deduct-guide.cpp" line="6"/>
1313
<attr id="has-trailing-return"/>
1414
<attr id="explicit-spec" name="explicit" value="1"/>
15-
<return type="X&lt;0&gt;"/>
15+
<return type="X&lt;0&gt;" id="7wllQWhGGsbbeoZVa3gh4d7bcq8="/>
1616
<param type="bool"/>
1717
</function>
1818
<function name="&lt;deduction guide for X&gt;" id="AtQyLakD3CjcM24GabAbHMNgVU4=">
1919
<file path="explicit-deduct-guide.cpp" line="8"/>
2020
<attr id="has-trailing-return"/>
2121
<attr id="explicit-spec" name="explicit(true)" value="3"/>
22-
<return type="X&lt;0&gt;"/>
22+
<return type="X&lt;0&gt;" id="7wllQWhGGsbbeoZVa3gh4d7bcq8="/>
2323
<param type="char"/>
2424
</function>
2525
<function name="&lt;deduction guide for X&gt;" id="tkYkUU6H8cbFpCU7yBuvBLkT6dg=">
2626
<file path="explicit-deduct-guide.cpp" line="10"/>
2727
<attr id="has-trailing-return"/>
2828
<attr id="explicit-spec" name="explicit(false)" value="2"/>
29-
<return type="X&lt;0&gt;"/>
29+
<return type="X&lt;0&gt;" id="7wllQWhGGsbbeoZVa3gh4d7bcq8="/>
3030
<param type="int"/>
3131
</function>
3232
<template>
@@ -35,7 +35,7 @@
3535
<file path="explicit-deduct-guide.cpp" line="13"/>
3636
<attr id="has-trailing-return"/>
3737
<attr id="explicit-spec" name="explicit(expr)" value="4"/>
38-
<return type="X&lt;0&gt;"/>
38+
<return type="X&lt;0&gt;" id="7wllQWhGGsbbeoZVa3gh4d7bcq8="/>
3939
<param type="long"/>
4040
</function>
4141
</template>

test-files/old-tests/function-parm-decay.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<file path="function-parm-decay.cpp" line="4"/>
88
<file path="function-parm-decay.cpp" line="5"/>
99
<file path="function-parm-decay.cpp" line="6"/>
10-
<param name="x" type="int"/>
10+
<param name="x" type="const int"/>
1111
</function>
1212
<function name="g" id="CJhykN8TDmEo0Pl8UC2D9+rotIs=">
1313
<file path="function-parm-decay.cpp" line="8"/>
@@ -21,7 +21,7 @@
2121
<file path="function-parm-decay.cpp" line="14"/>
2222
<file path="function-parm-decay.cpp" line="15"/>
2323
<file path="function-parm-decay.cpp" line="16"/>
24-
<param name="x" type="int (*)(bool)"/>
24+
<param name="x" type="int (bool)"/>
2525
</function>
2626
<alias name="T" id="PvNOREc+JWxdkVgvSz+jC45IbGQ=">
2727
<file path="function-parm-decay.cpp" line="18" class="def"/>
@@ -36,7 +36,7 @@
3636
<file path="function-parm-decay.cpp" line="22"/>
3737
<file path="function-parm-decay.cpp" line="23"/>
3838
<file path="function-parm-decay.cpp" line="24"/>
39-
<param type="T"/>
39+
<param type="T" id="PvNOREc+JWxdkVgvSz+jC45IbGQ="/>
4040
</function>
4141
</namespace>
4242
</mrdox>

test-files/old-tests/static-data-def-constexpr.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<file path="static-data-def-constexpr.cpp" line="5" class="def"/>
99
<file path="static-data-def-constexpr.cpp" line="3"/>
1010
<attr id="storage-class" name="static" value="2"/>
11-
<type name="S" id="pOYGF6pLJlICuiGO0Xj0daDb/to="/>
11+
<type name="const S" id="pOYGF6pLJlICuiGO0Xj0daDb/to="/>
1212
</variable>
1313
</struct>
1414
</namespace>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
struct A { };
2+
3+
template<typename T, typename U>
4+
struct B { };
5+
6+
using C = A;
7+
8+
using D = B<short, long>;
9+
10+
template<typename T>
11+
using E = B<T, long>;
12+
13+
void f0(A);
14+
void f1(const A);
15+
void f2(A&);
16+
void f3(const A&);
17+
void f4(A*);
18+
void f5(const A*);
19+
void f6(A**);
20+
void f7(const A**);
21+
void f8(const A* const*);
22+
23+
void g0(C);
24+
void g1(const C);
25+
void g2(C&);
26+
void g3(const C&);
27+
void g4(C*);
28+
void g5(const C*);
29+
void g6(C**);
30+
void g7(const C**);
31+
void g8(const C* const*);
32+
33+
void h0(B<short, long>);
34+
void h1(const B<short, long>);
35+
void h2(B<short, long>&);
36+
void h3(const B<short, long>&);
37+
void h4(B<short, long>*);
38+
void h5(const B<short, long>*);
39+
void h6(B<short, long>**);
40+
void h7(const B<short, long>**);
41+
void h8(const B<short, long>* const*);
42+
43+
void i0(D);
44+
void i1(const D);
45+
void i2(D&);
46+
void i3(const D&);
47+
void i4(D*);
48+
void i5(const D*);
49+
void i6(D**);
50+
void i7(const D**);
51+
void i8(const D* const*);
52+
53+
void j0(E<short>);
54+
void j1(const E<short>);
55+
void j2(E<short>&);
56+
void j3(const E<short>&);
57+
void j4(E<short>*);
58+
void j5(const E<short>*);
59+
void j6(E<short>**);
60+
void j7(const E<short>**);
61+
void j8(const E<short>* const*);

0 commit comments

Comments
 (0)