@@ -159,7 +159,8 @@ ASTVisitor(
159
159
bool
160
160
ASTVisitor::
161
161
extractSymbolID (
162
- SymbolID& id, const NamedDecl* D)
162
+ const Decl* D,
163
+ SymbolID& id)
163
164
{
164
165
usr_.clear ();
165
166
if (index ::generateUSRForDecl (D, usr_))
@@ -169,6 +170,16 @@ extractSymbolID(
169
170
return true ;
170
171
}
171
172
173
+ SymbolID
174
+ ASTVisitor::
175
+ extractSymbolID (
176
+ const Decl* D)
177
+ {
178
+ SymbolID id = SymbolID::zero;
179
+ extractSymbolID (D, id);
180
+ return id;
181
+ }
182
+
172
183
bool
173
184
ASTVisitor::
174
185
shouldSerializeInfo (
@@ -224,7 +235,7 @@ getParentNamespaces(
224
235
{
225
236
Namespace = N->getNameAsString ();
226
237
}
227
- extractSymbolID (id, N );
238
+ extractSymbolID (N, id );
228
239
Namespaces.emplace_back (
229
240
id,
230
241
Namespace,
@@ -259,15 +270,15 @@ getParentNamespaces(
259
270
}
260
271
Assert(TD);
261
272
262
- extractSymbolID(id, TD );
273
+ extractSymbolID(TD, id );
263
274
Namespaces.emplace_back(
264
275
id,
265
276
N->getNameAsString(),
266
277
InfoType::IT_record);
267
278
}
268
279
else if(const auto* N = dyn_cast<RecordDecl>(DC))
269
280
{
270
- extractSymbolID(id, N );
281
+ extractSymbolID(N, id );
271
282
Namespaces.emplace_back(
272
283
id,
273
284
N->getNameAsString(),
@@ -283,7 +294,7 @@ getParentNamespaces(
283
294
{
284
295
N = S->getTemplateInstantiationPattern ();
285
296
}
286
- extractSymbolID (id, N );
297
+ extractSymbolID (N, id );
287
298
Namespaces.emplace_back (
288
299
id,
289
300
N->getNameAsString (),
@@ -292,15 +303,15 @@ getParentNamespaces(
292
303
#endif
293
304
else if (const auto * N = dyn_cast<FunctionDecl>(DC))
294
305
{
295
- extractSymbolID (id, N );
306
+ extractSymbolID (N, id );
296
307
Namespaces.emplace_back (
297
308
id,
298
309
N->getNameAsString (),
299
310
InfoType::IT_function);
300
311
}
301
312
else if (const auto * N = dyn_cast<EnumDecl>(DC))
302
313
{
303
- extractSymbolID (id, N );
314
+ extractSymbolID (N, id );
304
315
Namespaces.emplace_back (
305
316
id,
306
317
N->getNameAsString (),
@@ -315,7 +326,7 @@ getParentNamespaces(
315
326
// (because this means it's in the global namespace).
316
327
// Also if its outermost namespace is a record because
317
328
// that record matches the previous condition mentioned.
318
- if ((Namespaces.empty () && isa<RecordDecl >(D)) ||
329
+ if ((Namespaces.empty () && isa<CXXRecordDecl >(D)) ||
319
330
(!Namespaces.empty () && Namespaces.back ().RefType == InfoType::IT_record))
320
331
{
321
332
Namespaces.emplace_back (
@@ -403,18 +414,17 @@ ASTVisitor::
403
414
getTypeInfoForType (
404
415
QualType T)
405
416
{
406
-
407
417
SymbolID id = SymbolID::zero;
408
418
if (const TagDecl* TD = getTagDeclForType (T))
409
419
{
410
420
InfoType IT;
411
421
if (isa<EnumDecl>(TD))
412
422
IT = InfoType::IT_enum;
413
- else if (isa<RecordDecl >(TD))
423
+ else if (isa<CXXRecordDecl >(TD))
414
424
IT = InfoType::IT_record;
415
425
else
416
426
IT = InfoType::IT_default;
417
- extractSymbolID (id, TD );
427
+ extractSymbolID (TD, id );
418
428
return TypeInfo (Reference (
419
429
id, TD->getNameAsString (), IT));
420
430
}
@@ -533,7 +543,7 @@ parseTemplateArgs(
533
543
{
534
544
if (auto * MT = primary->getInstantiatedFromMemberTemplate ())
535
545
primary = MT;
536
- extractSymbolID (I.Primary .emplace (), primary );
546
+ extractSymbolID (primary, I.Primary .emplace ());
537
547
}
538
548
// KRYSTIAN NOTE: when this is a partial specialization, we could use
539
549
// ClassTemplatePartialSpecializationDecl::getTemplateArgsAsWritten
@@ -557,7 +567,11 @@ parseTemplateArgs(
557
567
{
558
568
if (auto * MT = primary->getInstantiatedFromMemberTemplate ())
559
569
primary = MT;
560
- extractSymbolID (I.Primary .emplace (), primary);
570
+ // unlike function and class templates, the USR generated
571
+ // for variable templates differs from that of the VarDecl
572
+ // returned by getTemplatedDecl. this might be a clang bug.
573
+ // the USR of the templated VarDecl seems to be the correct one.
574
+ extractSymbolID (primary->getTemplatedDecl (), I.Primary .emplace ());
561
575
}
562
576
563
577
// spec->getTemplateArgsInfo()
@@ -588,7 +602,7 @@ parseTemplateArgs(
588
602
{
589
603
if (auto * MT = primary->getInstantiatedFromMemberTemplate ())
590
604
primary = MT;
591
- extractSymbolID (I.Primary .emplace (), primary );
605
+ extractSymbolID (primary, I.Primary .emplace ());
592
606
}
593
607
if (auto * args = spec->TemplateArguments )
594
608
{
@@ -828,7 +842,7 @@ parseEnumerators(
828
842
bool
829
843
ASTVisitor::
830
844
shouldExtract (
831
- Decl const * D)
845
+ const Decl * D)
832
846
{
833
847
namespace path = llvm::sys::path;
834
848
@@ -881,12 +895,12 @@ bool
881
895
ASTVisitor::
882
896
extractInfo (
883
897
Info& I,
884
- NamedDecl const * D)
898
+ const NamedDecl * D)
885
899
{
886
900
bool anonymous = getParentNamespaces (I.Namespace , D);
887
901
if (! shouldSerializeInfo (PublicOnly, anonymous, D))
888
902
return false ;
889
- if (! extractSymbolID (I.id , D ))
903
+ if (! extractSymbolID (D, I.id ))
890
904
return false ;
891
905
I.Name = D->getNameAsString ();
892
906
parseRawComment (I.javadoc , D, R_);
@@ -915,16 +929,16 @@ extractBases(
915
929
if (auto const * Ty = B.getType ()->getAs <TemplateSpecializationType>())
916
930
{
917
931
TemplateDecl const * TD = Ty->getTemplateName ().getAsTemplateDecl ();
918
- extractSymbolID (id, TD );
932
+ extractSymbolID (TD, id );
919
933
I.Bases .emplace_back (
920
934
id,
921
935
getTypeAsString (B.getType ()),
922
936
getAccessFromSpecifier (B.getAccessSpecifier ()),
923
937
isVirtual);
924
938
}
925
- else if (RecordDecl const * P = getCXXRecordDeclForType (B.getType ()))
939
+ else if (CXXRecordDecl const * P = getCXXRecordDeclForType (B.getType ()))
926
940
{
927
- extractSymbolID (id, P );
941
+ extractSymbolID (P, id );
928
942
I.Bases .emplace_back (
929
943
id,
930
944
P->getNameAsString (),
@@ -1157,10 +1171,10 @@ buildFriend(
1157
1171
getParent(id, D);
1158
1172
#else
1159
1173
const DeclContext* DC = D->getDeclContext ();
1160
- const auto * RD = dyn_cast<RecordDecl >(DC);
1174
+ const auto * RD = dyn_cast<CXXRecordDecl >(DC);
1161
1175
Assert (RD && " the semantic DeclContext of a FriendDecl must be a class" );
1162
1176
RecordInfo P;
1163
- extractSymbolID (P.id , RD );
1177
+ extractSymbolID (RD, P.id );
1164
1178
1165
1179
#if 0
1166
1180
SymbolID id_;
@@ -1677,7 +1691,26 @@ TraverseDecl(
1677
1691
#if 1
1678
1692
if (D->isImplicit ())
1679
1693
return true ;
1680
- #else
1694
+ #elif 1
1695
+ {
1696
+
1697
+ if (D->isImplicit ())
1698
+ {
1699
+ if (! encountered_explicit_)
1700
+ return true ;
1701
+ print_debug (" {:<64}{:<32} ID = {}\n " , std::format (
1702
+ " {}(implicit) {}" , indent (context_depth_), D->getDeclKindName ()),
1703
+ getDeclName (D), extractSymbolID (D));
1704
+ return true ;
1705
+ }
1706
+ encountered_explicit_ = true ;
1707
+
1708
+ print_debug (" {:<64}{:<32} ID = {}\n " , std::format (
1709
+ " {}{}" , indent (context_depth_), D->getDeclKindName ()),
1710
+ getDeclName (D), extractSymbolID (D));
1711
+ print_debug (" {} {}\n " , indent (context_depth_), usr_.c_str ());
1712
+ }
1713
+ #elif 1
1681
1714
{
1682
1715
auto specs = getNumSpecializations (D);
1683
1716
std::string specs_str = specs.has_value () ?
0 commit comments