@@ -62,20 +62,17 @@ namespace {
62
62
class USRGenerator : public ConstDeclVisitor <USRGenerator> {
63
63
SmallVectorImpl<char > &Buf;
64
64
llvm::raw_svector_ostream Out;
65
- bool IgnoreResults;
66
65
ASTContext *Context;
67
- bool generatedLoc;
66
+ const LangOptions &LangOpts;
67
+ bool IgnoreResults = false ;
68
+ bool generatedLoc = false ;
68
69
69
70
llvm::DenseMap<const Type *, unsigned > TypeSubstitutions;
70
71
71
72
public:
72
- explicit USRGenerator (ASTContext *Ctx, SmallVectorImpl<char > &Buf)
73
- : Buf(Buf),
74
- Out(Buf),
75
- IgnoreResults(false ),
76
- Context(Ctx),
77
- generatedLoc(false )
78
- {
73
+ USRGenerator (ASTContext *Ctx, SmallVectorImpl<char > &Buf,
74
+ const LangOptions &LangOpts)
75
+ : Buf(Buf), Out(Buf), Context(Ctx), LangOpts(LangOpts) {
79
76
// Add the USR space prefix.
80
77
Out << getUSRSpacePrefix ();
81
78
}
@@ -246,14 +243,13 @@ void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) {
246
243
} else
247
244
Out << " @F@" ;
248
245
249
- PrintingPolicy Policy (Context-> getLangOpts () );
246
+ PrintingPolicy Policy (LangOpts );
250
247
// Forward references can have different template argument names. Suppress the
251
248
// template argument names in constructors to make their USR more stable.
252
249
Policy.SuppressTemplateArgsInCXXConstructors = true ;
253
250
D->getDeclName ().print (Out, Policy);
254
251
255
- ASTContext &Ctx = *Context;
256
- if ((!Ctx.getLangOpts ().CPlusPlus || D->isExternC ()) &&
252
+ if ((!LangOpts.CPlusPlus || D->isExternC ()) &&
257
253
!D->hasAttr <OverloadableAttr>())
258
254
return ;
259
255
@@ -657,9 +653,10 @@ bool USRGenerator::GenLoc(const Decl *D, bool IncludeOffset) {
657
653
return IgnoreResults;
658
654
}
659
655
660
- static void printQualifier (llvm::raw_ostream &Out, ASTContext &Ctx, NestedNameSpecifier *NNS) {
656
+ static void printQualifier (llvm::raw_ostream &Out, const LangOptions &LangOpts,
657
+ NestedNameSpecifier *NNS) {
661
658
// FIXME: Encode the qualifier, don't just print it.
662
- PrintingPolicy PO (Ctx. getLangOpts () );
659
+ PrintingPolicy PO (LangOpts );
663
660
PO.SuppressTagKeyword = true ;
664
661
PO.SuppressUnwrittenScope = true ;
665
662
PO.ConstantArraySizeAsWritten = false ;
@@ -948,7 +945,7 @@ void USRGenerator::VisitType(QualType T) {
948
945
}
949
946
if (const DependentNameType *DNT = T->getAs <DependentNameType>()) {
950
947
Out << ' ^' ;
951
- printQualifier (Out, Ctx , DNT->getQualifier ());
948
+ printQualifier (Out, LangOpts , DNT->getQualifier ());
952
949
Out << ' :' << DNT->getIdentifier ()->getName ();
953
950
return ;
954
951
}
@@ -1090,7 +1087,7 @@ void USRGenerator::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl
1090
1087
return ;
1091
1088
VisitDeclContext (D->getDeclContext ());
1092
1089
Out << " @UUV@" ;
1093
- printQualifier (Out, D-> getASTContext () , D->getQualifier ());
1090
+ printQualifier (Out, LangOpts , D->getQualifier ());
1094
1091
EmitDeclName (D);
1095
1092
}
1096
1093
@@ -1099,7 +1096,7 @@ void USRGenerator::VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenam
1099
1096
return ;
1100
1097
VisitDeclContext (D->getDeclContext ());
1101
1098
Out << " @UUT@" ;
1102
- printQualifier (Out, D-> getASTContext () , D->getQualifier ());
1099
+ printQualifier (Out, LangOpts , D->getQualifier ());
1103
1100
Out << D->getName (); // Simple name.
1104
1101
}
1105
1102
@@ -1190,6 +1187,13 @@ bool clang::index::generateUSRForDecl(const Decl *D,
1190
1187
SmallVectorImpl<char > &Buf) {
1191
1188
if (!D)
1192
1189
return true ;
1190
+ return generateUSRForDecl (D, Buf, D->getASTContext ().getLangOpts ());
1191
+ }
1192
+
1193
+ bool clang::index::generateUSRForDecl (const Decl *D, SmallVectorImpl<char > &Buf,
1194
+ const LangOptions &LangOpts) {
1195
+ if (!D)
1196
+ return true ;
1193
1197
// We don't ignore decls with invalid source locations. Implicit decls, like
1194
1198
// C++'s operator new function, can have invalid locations but it is fine to
1195
1199
// create USRs that can identify them.
@@ -1203,7 +1207,7 @@ bool clang::index::generateUSRForDecl(const Decl *D,
1203
1207
return false ;
1204
1208
}
1205
1209
}
1206
- USRGenerator UG (&D->getASTContext (), Buf);
1210
+ USRGenerator UG (&D->getASTContext (), Buf, LangOpts );
1207
1211
UG.Visit (D);
1208
1212
return UG.ignoreResults ();
1209
1213
}
@@ -1240,11 +1244,17 @@ bool clang::index::generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
1240
1244
1241
1245
bool clang::index::generateUSRForType (QualType T, ASTContext &Ctx,
1242
1246
SmallVectorImpl<char > &Buf) {
1247
+ return generateUSRForType (T, Ctx, Buf, Ctx.getLangOpts ());
1248
+ }
1249
+
1250
+ bool clang::index::generateUSRForType (QualType T, ASTContext &Ctx,
1251
+ SmallVectorImpl<char > &Buf,
1252
+ const LangOptions &LangOpts) {
1243
1253
if (T.isNull ())
1244
1254
return true ;
1245
1255
T = T.getCanonicalType ();
1246
1256
1247
- USRGenerator UG (&Ctx, Buf);
1257
+ USRGenerator UG (&Ctx, Buf, LangOpts );
1248
1258
UG.VisitType (T);
1249
1259
return UG.ignoreResults ();
1250
1260
}
0 commit comments