Skip to content

Commit 0c92edd

Browse files
committed
parse fields with Traverse(FieldDecl*)
1 parent cfbd0bb commit 0c92edd

File tree

4 files changed

+198
-44
lines changed

4 files changed

+198
-44
lines changed

source/AST/ASTVisitor.cpp

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -804,41 +804,6 @@ writeParent(
804804
return writeBitcode(P);
805805
}
806806

807-
void
808-
ASTVisitor::
809-
parseFields(
810-
RecordInfo& I,
811-
const RecordDecl* D,
812-
bool PublicOnly,
813-
AccessSpecifier Access,
814-
Reporter& R)
815-
{
816-
static_cast<void>(I);
817-
static_cast<void>(PublicOnly);
818-
static_cast<void>(Access);
819-
static_cast<void>(R);
820-
for(const FieldDecl* F : D->fields())
821-
{
822-
FieldInfo FI;
823-
if(! extractInfo(FI, F))
824-
continue;
825-
LineNumber = getLine(F);
826-
FI.DefLoc.emplace(LineNumber, File, IsFileInRootDir);
827-
828-
FI.Type = getTypeInfoForType(
829-
F->getTypeSourceInfo()->getType());
830-
831-
832-
FI.specs.hasNoUniqueAddress = F->hasAttr<NoUniqueAddressAttr>();
833-
FI.specs.isDeprecated = F->hasAttr<DeprecatedAttr>();
834-
// KRYSTIAN FIXME: isNodiscard should be isMaybeUnused
835-
FI.specs.isNodiscard = F->hasAttr<UnusedAttr>();
836-
837-
insertBitcode(ex_, writeBitcode(FI));
838-
insertBitcode(ex_, writeParent(FI, F->getAccess()));
839-
}
840-
}
841-
842807
void
843808
ASTVisitor::
844809
parseEnumerators(
@@ -1137,7 +1102,6 @@ buildRecord(
11371102
else
11381103
I.Loc.emplace_back(LineNumber, File, IsFileInRootDir);
11391104
I.TagType = D->getTagKind();
1140-
parseFields(I, D, PublicOnly, AccessSpecifier::AS_public, R_);
11411105

11421106
// These are from CXXRecordDecl::isEffectivelyFinal()
11431107
I.specs.isFinal = D->template hasAttr<FinalAttr>();
@@ -1270,6 +1234,29 @@ buildEnum(
12701234
insertBitcode(ex_, writeParent(I, D->getAccess()));
12711235
}
12721236

1237+
void
1238+
ASTVisitor::
1239+
buildField(
1240+
FieldInfo& I,
1241+
FieldDecl* D)
1242+
{
1243+
if(! extractInfo(I, D))
1244+
return;
1245+
LineNumber = getLine(D);
1246+
I.DefLoc.emplace(LineNumber, File, IsFileInRootDir);
1247+
1248+
I.Type = getTypeInfoForType(
1249+
D->getTypeSourceInfo()->getType());
1250+
1251+
I.specs.hasNoUniqueAddress = D->hasAttr<NoUniqueAddressAttr>();
1252+
I.specs.isDeprecated = D->hasAttr<DeprecatedAttr>();
1253+
// KRYSTIAN FIXME: isNodiscard should be isMaybeUnused
1254+
I.specs.isNodiscard = D->hasAttr<UnusedAttr>();
1255+
1256+
insertBitcode(ex_, writeBitcode(I));
1257+
insertBitcode(ex_, writeParent(I, D->getAccess()));
1258+
}
1259+
12731260
void
12741261
ASTVisitor::
12751262
buildVar(
@@ -1516,6 +1503,18 @@ Traverse(
15161503
return true;
15171504
}
15181505

1506+
bool
1507+
ASTVisitor::
1508+
Traverse(
1509+
FieldDecl* D)
1510+
{
1511+
if(! shouldExtract(D))
1512+
return true;
1513+
FieldInfo I;
1514+
buildField(I, D);
1515+
return true;
1516+
}
1517+
15191518
bool
15201519
ASTVisitor::
15211520
Traverse(
@@ -1760,6 +1759,11 @@ TraverseDecl(
17601759
EnumDecl*>(D),
17611760
std::forward<Args>(args)...);
17621761
break;
1762+
case Decl::Field:
1763+
this->Traverse(static_cast<
1764+
FieldDecl*>(D),
1765+
std::forward<Args>(args)...);
1766+
break;
17631767
case Decl::Var:
17641768
this->Traverse(static_cast<
17651769
VarDecl*>(D),

source/AST/ASTVisitor.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,6 @@ class ASTVisitor
169169
Decl const* D,
170170
Reporter& R);
171171

172-
void
173-
parseFields(
174-
RecordInfo& I,
175-
const RecordDecl* D,
176-
bool PublicOnly,
177-
AccessSpecifier Access,
178-
Reporter& R);
179-
180172
void
181173
parseEnumerators(
182174
EnumInfo& I,
@@ -211,6 +203,10 @@ class ASTVisitor
211203
EnumInfo& I,
212204
EnumDecl* D);
213205

206+
void buildField(
207+
FieldInfo& I,
208+
FieldDecl* D);
209+
214210
void buildVar(
215211
VarInfo& I,
216212
VarDecl* D);
@@ -244,6 +240,7 @@ class ASTVisitor
244240
bool Traverse(CXXDestructorDecl* D);
245241
bool Traverse(FriendDecl* D);
246242
bool Traverse(EnumDecl* D);
243+
bool Traverse(FieldDecl* D);
247244

248245
bool Traverse(ClassTemplateDecl* D);
249246
bool Traverse(ClassTemplateSpecializationDecl* D);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
struct S { };
2+
3+
template<typename T>
4+
struct C0
5+
{
6+
int w;
7+
S x;
8+
T y;
9+
10+
struct N0
11+
{
12+
int z;
13+
};
14+
};
15+
16+
struct C1
17+
{
18+
int w;
19+
20+
template<typename T>
21+
struct N1
22+
{
23+
S x;
24+
T y;
25+
int z;
26+
};
27+
};
28+
29+
template<typename T>
30+
struct C2
31+
{
32+
int v;
33+
34+
template<typename U>
35+
struct N2
36+
{
37+
S w;
38+
T x;
39+
U y;
40+
int z;
41+
};
42+
};
43+
44+
template<typename T>
45+
struct C3;
46+
47+
template<typename T>
48+
struct C3
49+
{
50+
int v;
51+
};
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mrdox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdox/raw/develop/mrdox.rnc">
4+
<namespace name="">
5+
<struct name="C2" id="IIPz8Fm6nqKoYQpeJ/kvZaWvtI8=">
6+
<file path="class-template.cpp" line="30" class="def"/>
7+
<template>
8+
<tparam name="T" class="type"/>
9+
</template>
10+
<struct name="N2" id="xljI5oOqNOhyyR4QzmKvFB3nEfw=">
11+
<file path="class-template.cpp" line="35" class="def"/>
12+
<template>
13+
<tparam name="U" class="type"/>
14+
</template>
15+
<data name="w" id="bLX5mthqXMHAtLNEc87RKLQSUyU=">
16+
<file path="class-template.cpp" line="37" class="def"/>
17+
<type name="S" id="pOYGF6pLJlICuiGO0Xj0daDb/to="/>
18+
</data>
19+
<data name="x" id="qSNOAAxaet7aBxvD7WvFqJOpm3A=">
20+
<file path="class-template.cpp" line="38" class="def"/>
21+
<type name="T"/>
22+
</data>
23+
<data name="y" id="P9x8qHxDv7huDL0MyNORJ/enU0Q=">
24+
<file path="class-template.cpp" line="39" class="def"/>
25+
<type name="U"/>
26+
</data>
27+
<data name="z" id="pRO2j7I5aEQI+ktDwT1fLJPqy28=">
28+
<file path="class-template.cpp" line="40" class="def"/>
29+
<type name="int"/>
30+
</data>
31+
</struct>
32+
<data name="v" id="rvAO5HvzEvS8z9PgbRoqkyTi+1c=">
33+
<file path="class-template.cpp" line="32" class="def"/>
34+
<type name="int"/>
35+
</data>
36+
</struct>
37+
<struct name="S" id="pOYGF6pLJlICuiGO0Xj0daDb/to=">
38+
<file path="class-template.cpp" line="1" class="def"/>
39+
</struct>
40+
<struct name="C0" id="sv7ww7qclY8KsvAbFHXaKZnSO80=">
41+
<file path="class-template.cpp" line="4" class="def"/>
42+
<template>
43+
<tparam name="T" class="type"/>
44+
</template>
45+
<struct name="N0" id="gx6LdMT9nBMQKB26lZXGWbB7N6c=">
46+
<file path="class-template.cpp" line="10" class="def"/>
47+
<data name="z" id="sdv932bFyf1dJzPblqxQGqsy8G4=">
48+
<file path="class-template.cpp" line="12" class="def"/>
49+
<type name="int"/>
50+
</data>
51+
</struct>
52+
<data name="w" id="ySFHEWJe6/b1dbtjDC2IAvT2vmU=">
53+
<file path="class-template.cpp" line="6" class="def"/>
54+
<type name="int"/>
55+
</data>
56+
<data name="x" id="81imwKxfuTfd7lfVGnF+fKx46lY=">
57+
<file path="class-template.cpp" line="7" class="def"/>
58+
<type name="S" id="pOYGF6pLJlICuiGO0Xj0daDb/to="/>
59+
</data>
60+
<data name="y" id="UKBRhwzQ0PeL6ZwfxmreRBoDQSY=">
61+
<file path="class-template.cpp" line="8" class="def"/>
62+
<type name="T"/>
63+
</data>
64+
</struct>
65+
<struct name="C1" id="tm2khHa6qZM0lj1f7IwBdxVxDgE=">
66+
<file path="class-template.cpp" line="16" class="def"/>
67+
<struct name="N1" id="F1Cyqn/faLYbjTU4RfGsepUiiZw=">
68+
<file path="class-template.cpp" line="21" class="def"/>
69+
<template>
70+
<tparam name="T" class="type"/>
71+
</template>
72+
<data name="x" id="bQCgblScrSKOxQMVJxT7vFw9W4I=">
73+
<file path="class-template.cpp" line="23" class="def"/>
74+
<type name="S" id="pOYGF6pLJlICuiGO0Xj0daDb/to="/>
75+
</data>
76+
<data name="y" id="phg6+zMhjV0SJ7vav871OGqoPPQ=">
77+
<file path="class-template.cpp" line="24" class="def"/>
78+
<type name="T"/>
79+
</data>
80+
<data name="z" id="53ijFg2EUlLuOP8qvufgjwZDNoI=">
81+
<file path="class-template.cpp" line="25" class="def"/>
82+
<type name="int"/>
83+
</data>
84+
</struct>
85+
<data name="w" id="Q0itZUB0O9hts+pFPk9DO415Lo8=">
86+
<file path="class-template.cpp" line="18" class="def"/>
87+
<type name="int"/>
88+
</data>
89+
</struct>
90+
<struct name="C3" id="x60FzYL65XgZZRrxrZuC5jemrwQ=">
91+
<file path="class-template.cpp" line="48" class="def"/>
92+
<file path="class-template.cpp" line="45"/>
93+
<template>
94+
<tparam name="T" class="type"/>
95+
</template>
96+
<data name="v" id="28J+g16kE2M7qwnrP4yzW4hHlIg=">
97+
<file path="class-template.cpp" line="50" class="def"/>
98+
<type name="int"/>
99+
</data>
100+
</struct>
101+
</namespace>
102+
</mrdox>

0 commit comments

Comments
 (0)