clang  16.0.0git
USRGeneration.cpp
Go to the documentation of this file.
1 //===- USRGeneration.cpp - Routines for USR generation --------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "clang/AST/ASTContext.h"
11 #include "clang/AST/Attr.h"
12 #include "clang/AST/DeclTemplate.h"
13 #include "clang/AST/DeclVisitor.h"
16 #include "llvm/Support/Path.h"
17 #include "llvm/Support/raw_ostream.h"
18 
19 using namespace clang;
20 using namespace clang::index;
21 
22 //===----------------------------------------------------------------------===//
23 // USR generation.
24 //===----------------------------------------------------------------------===//
25 
26 /// \returns true on error.
27 static bool printLoc(llvm::raw_ostream &OS, SourceLocation Loc,
28  const SourceManager &SM, bool IncludeOffset) {
29  if (Loc.isInvalid()) {
30  return true;
31  }
32  Loc = SM.getExpansionLoc(Loc);
33  const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(Loc);
34  const FileEntry *FE = SM.getFileEntryForID(Decomposed.first);
35  if (FE) {
36  OS << llvm::sys::path::filename(FE->getName());
37  } else {
38  // This case really isn't interesting.
39  return true;
40  }
41  if (IncludeOffset) {
42  // Use the offest into the FileID to represent the location. Using
43  // a line/column can cause us to look back at the original source file,
44  // which is expensive.
45  OS << '@' << Decomposed.second;
46  }
47  return false;
48 }
49 
50 static StringRef GetExternalSourceContainer(const NamedDecl *D) {
51  if (!D)
52  return StringRef();
53  if (auto *attr = D->getExternalSourceSymbolAttr()) {
54  return attr->getDefinedIn();
55  }
56  return StringRef();
57 }
58 
59 namespace {
60 class USRGenerator : public ConstDeclVisitor<USRGenerator> {
62  llvm::raw_svector_ostream Out;
63  bool IgnoreResults;
64  ASTContext *Context;
65  bool generatedLoc;
66 
67  llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
68 
69 public:
70  explicit USRGenerator(ASTContext *Ctx, SmallVectorImpl<char> &Buf)
71  : Buf(Buf),
72  Out(Buf),
73  IgnoreResults(false),
74  Context(Ctx),
75  generatedLoc(false)
76  {
77  // Add the USR space prefix.
78  Out << getUSRSpacePrefix();
79  }
80 
81  bool ignoreResults() const { return IgnoreResults; }
82 
83  // Visitation methods from generating USRs from AST elements.
84  void VisitDeclContext(const DeclContext *D);
85  void VisitFieldDecl(const FieldDecl *D);
86  void VisitFunctionDecl(const FunctionDecl *D);
87  void VisitNamedDecl(const NamedDecl *D);
88  void VisitNamespaceDecl(const NamespaceDecl *D);
89  void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
90  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
91  void VisitClassTemplateDecl(const ClassTemplateDecl *D);
92  void VisitObjCContainerDecl(const ObjCContainerDecl *CD,
93  const ObjCCategoryDecl *CatD = nullptr);
94  void VisitObjCMethodDecl(const ObjCMethodDecl *MD);
95  void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
96  void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
97  void VisitTagDecl(const TagDecl *D);
98  void VisitTypedefDecl(const TypedefDecl *D);
99  void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
100  void VisitVarDecl(const VarDecl *D);
101  void VisitBindingDecl(const BindingDecl *D);
102  void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
103  void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
104  void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
105  void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
106  void VisitConceptDecl(const ConceptDecl *D);
107 
108  void VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
109  IgnoreResults = true; // No USRs for linkage specs themselves.
110  }
111 
112  void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
113  IgnoreResults = true;
114  }
115 
116  void VisitUsingDecl(const UsingDecl *D) {
117  VisitDeclContext(D->getDeclContext());
118  Out << "@UD@";
119 
120  bool EmittedDeclName = !EmitDeclName(D);
121  assert(EmittedDeclName && "EmitDeclName can not fail for UsingDecls");
122  (void)EmittedDeclName;
123  }
124 
125  bool ShouldGenerateLocation(const NamedDecl *D);
126 
127  bool isLocal(const NamedDecl *D) {
128  return D->getParentFunctionOrMethod() != nullptr;
129  }
130 
131  void GenExtSymbolContainer(const NamedDecl *D);
132 
133  /// Generate the string component containing the location of the
134  /// declaration.
135  bool GenLoc(const Decl *D, bool IncludeOffset);
136 
137  /// String generation methods used both by the visitation methods
138  /// and from other clients that want to directly generate USRs. These
139  /// methods do not construct complete USRs (which incorporate the parents
140  /// of an AST element), but only the fragments concerning the AST element
141  /// itself.
142 
143  /// Generate a USR for an Objective-C class.
144  void GenObjCClass(StringRef cls, StringRef ExtSymDefinedIn,
145  StringRef CategoryContextExtSymbolDefinedIn) {
146  generateUSRForObjCClass(cls, Out, ExtSymDefinedIn,
147  CategoryContextExtSymbolDefinedIn);
148  }
149 
150  /// Generate a USR for an Objective-C class category.
151  void GenObjCCategory(StringRef cls, StringRef cat,
152  StringRef clsExt, StringRef catExt) {
153  generateUSRForObjCCategory(cls, cat, Out, clsExt, catExt);
154  }
155 
156  /// Generate a USR fragment for an Objective-C property.
157  void GenObjCProperty(StringRef prop, bool isClassProp) {
158  generateUSRForObjCProperty(prop, isClassProp, Out);
159  }
160 
161  /// Generate a USR for an Objective-C protocol.
162  void GenObjCProtocol(StringRef prot, StringRef ext) {
163  generateUSRForObjCProtocol(prot, Out, ext);
164  }
165 
166  void VisitType(QualType T);
167  void VisitTemplateParameterList(const TemplateParameterList *Params);
168  void VisitTemplateName(TemplateName Name);
169  void VisitTemplateArgument(const TemplateArgument &Arg);
170 
171  void VisitMSGuidDecl(const MSGuidDecl *D);
172 
173  /// Emit a Decl's name using NamedDecl::printName() and return true if
174  /// the decl had no name.
175  bool EmitDeclName(const NamedDecl *D);
176 };
177 } // end anonymous namespace
178 
179 //===----------------------------------------------------------------------===//
180 // Generating USRs from ASTS.
181 //===----------------------------------------------------------------------===//
182 
183 bool USRGenerator::EmitDeclName(const NamedDecl *D) {
184  DeclarationName N = D->getDeclName();
185  if (N.isEmpty())
186  return true;
187  Out << N;
188  return false;
189 }
190 
191 bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) {
192  if (D->isExternallyVisible())
193  return false;
194  if (D->getParentFunctionOrMethod())
195  return true;
196  SourceLocation Loc = D->getLocation();
197  if (Loc.isInvalid())
198  return false;
199  const SourceManager &SM = Context->getSourceManager();
200  return !SM.isInSystemHeader(Loc);
201 }
202 
203 void USRGenerator::VisitDeclContext(const DeclContext *DC) {
204  if (const NamedDecl *D = dyn_cast<NamedDecl>(DC))
205  Visit(D);
206  else if (isa<LinkageSpecDecl>(DC)) // Linkage specs are transparent in USRs.
207  VisitDeclContext(DC->getParent());
208 }
209 
210 void USRGenerator::VisitFieldDecl(const FieldDecl *D) {
211  // The USR for an ivar declared in a class extension is based on the
212  // ObjCInterfaceDecl, not the ObjCCategoryDecl.
213  if (const ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
214  Visit(ID);
215  else
216  VisitDeclContext(D->getDeclContext());
217  Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@");
218  if (EmitDeclName(D)) {
219  // Bit fields can be anonymous.
220  IgnoreResults = true;
221  return;
222  }
223 }
224 
225 void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) {
226  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
227  return;
228 
229  const unsigned StartSize = Buf.size();
230  VisitDeclContext(D->getDeclContext());
231  if (Buf.size() == StartSize)
232  GenExtSymbolContainer(D);
233 
234  bool IsTemplate = false;
236  IsTemplate = true;
237  Out << "@FT@";
238  VisitTemplateParameterList(FunTmpl->getTemplateParameters());
239  } else
240  Out << "@F@";
241 
242  PrintingPolicy Policy(Context->getLangOpts());
243  // Forward references can have different template argument names. Suppress the
244  // template argument names in constructors to make their USR more stable.
245  Policy.SuppressTemplateArgsInCXXConstructors = true;
246  D->getDeclName().print(Out, Policy);
247 
248  ASTContext &Ctx = *Context;
249  if ((!Ctx.getLangOpts().CPlusPlus || D->isExternC()) &&
250  !D->hasAttr<OverloadableAttr>())
251  return;
252 
253  if (const TemplateArgumentList *
254  SpecArgs = D->getTemplateSpecializationArgs()) {
255  Out << '<';
256  for (unsigned I = 0, N = SpecArgs->size(); I != N; ++I) {
257  Out << '#';
258  VisitTemplateArgument(SpecArgs->get(I));
259  }
260  Out << '>';
261  }
262 
263  // Mangle in type information for the arguments.
264  for (auto *PD : D->parameters()) {
265  Out << '#';
266  VisitType(PD->getType());
267  }
268  if (D->isVariadic())
269  Out << '.';
270  if (IsTemplate) {
271  // Function templates can be overloaded by return type, for example:
272  // \code
273  // template <class T> typename T::A foo() {}
274  // template <class T> typename T::B foo() {}
275  // \endcode
276  Out << '#';
277  VisitType(D->getReturnType());
278  }
279  Out << '#';
280  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
281  if (MD->isStatic())
282  Out << 'S';
283  // FIXME: OpenCL: Need to consider address spaces
284  if (unsigned quals = MD->getMethodQualifiers().getCVRUQualifiers())
285  Out << (char)('0' + quals);
286  switch (MD->getRefQualifier()) {
287  case RQ_None: break;
288  case RQ_LValue: Out << '&'; break;
289  case RQ_RValue: Out << "&&"; break;
290  }
291  }
292 }
293 
294 void USRGenerator::VisitNamedDecl(const NamedDecl *D) {
295  VisitDeclContext(D->getDeclContext());
296  Out << "@";
297 
298  if (EmitDeclName(D)) {
299  // The string can be empty if the declaration has no name; e.g., it is
300  // the ParmDecl with no name for declaration of a function pointer type,
301  // e.g.: void (*f)(void *);
302  // In this case, don't generate a USR.
303  IgnoreResults = true;
304  }
305 }
306 
307 void USRGenerator::VisitVarDecl(const VarDecl *D) {
308  // VarDecls can be declared 'extern' within a function or method body,
309  // but their enclosing DeclContext is the function, not the TU. We need
310  // to check the storage class to correctly generate the USR.
311  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
312  return;
313 
314  VisitDeclContext(D->getDeclContext());
315 
316  if (VarTemplateDecl *VarTmpl = D->getDescribedVarTemplate()) {
317  Out << "@VT";
318  VisitTemplateParameterList(VarTmpl->getTemplateParameters());
319  } else if (const VarTemplatePartialSpecializationDecl *PartialSpec
320  = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
321  Out << "@VP";
322  VisitTemplateParameterList(PartialSpec->getTemplateParameters());
323  }
324 
325  // Variables always have simple names.
326  StringRef s = D->getName();
327 
328  // The string can be empty if the declaration has no name; e.g., it is
329  // the ParmDecl with no name for declaration of a function pointer type, e.g.:
330  // void (*f)(void *);
331  // In this case, don't generate a USR.
332  if (s.empty())
333  IgnoreResults = true;
334  else
335  Out << '@' << s;
336 
337  // For a template specialization, mangle the template arguments.
338  if (const VarTemplateSpecializationDecl *Spec
339  = dyn_cast<VarTemplateSpecializationDecl>(D)) {
340  const TemplateArgumentList &Args = Spec->getTemplateArgs();
341  Out << '>';
342  for (unsigned I = 0, N = Args.size(); I != N; ++I) {
343  Out << '#';
344  VisitTemplateArgument(Args.get(I));
345  }
346  }
347 }
348 
349 void USRGenerator::VisitBindingDecl(const BindingDecl *D) {
350  if (isLocal(D) && GenLoc(D, /*IncludeOffset=*/true))
351  return;
352  VisitNamedDecl(D);
353 }
354 
355 void USRGenerator::VisitNonTypeTemplateParmDecl(
356  const NonTypeTemplateParmDecl *D) {
357  GenLoc(D, /*IncludeOffset=*/true);
358 }
359 
360 void USRGenerator::VisitTemplateTemplateParmDecl(
361  const TemplateTemplateParmDecl *D) {
362  GenLoc(D, /*IncludeOffset=*/true);
363 }
364 
365 void USRGenerator::VisitNamespaceDecl(const NamespaceDecl *D) {
366  if (D->isAnonymousNamespace()) {
367  Out << "@aN";
368  return;
369  }
370 
371  VisitDeclContext(D->getDeclContext());
372  if (!IgnoreResults)
373  Out << "@N@" << D->getName();
374 }
375 
376 void USRGenerator::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
377  VisitFunctionDecl(D->getTemplatedDecl());
378 }
379 
380 void USRGenerator::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
381  VisitTagDecl(D->getTemplatedDecl());
382 }
383 
384 void USRGenerator::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
385  VisitDeclContext(D->getDeclContext());
386  if (!IgnoreResults)
387  Out << "@NA@" << D->getName();
388 }
389 
390 static const ObjCCategoryDecl *getCategoryContext(const NamedDecl *D) {
391  if (auto *CD = dyn_cast<ObjCCategoryDecl>(D->getDeclContext()))
392  return CD;
393  if (auto *ICD = dyn_cast<ObjCCategoryImplDecl>(D->getDeclContext()))
394  return ICD->getCategoryDecl();
395  return nullptr;
396 }
397 
398 void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
399  const DeclContext *container = D->getDeclContext();
400  if (const ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
401  Visit(pd);
402  }
403  else {
404  // The USR for a method declared in a class extension or category is based on
405  // the ObjCInterfaceDecl, not the ObjCCategoryDecl.
406  const ObjCInterfaceDecl *ID = D->getClassInterface();
407  if (!ID) {
408  IgnoreResults = true;
409  return;
410  }
411  auto *CD = getCategoryContext(D);
412  VisitObjCContainerDecl(ID, CD);
413  }
414  // Ideally we would use 'GenObjCMethod', but this is such a hot path
415  // for Objective-C code that we don't want to use
416  // DeclarationName::getAsString().
417  Out << (D->isInstanceMethod() ? "(im)" : "(cm)")
418  << DeclarationName(D->getSelector());
419 }
420 
421 void USRGenerator::VisitObjCContainerDecl(const ObjCContainerDecl *D,
422  const ObjCCategoryDecl *CatD) {
423  switch (D->getKind()) {
424  default:
425  llvm_unreachable("Invalid ObjC container.");
426  case Decl::ObjCInterface:
427  case Decl::ObjCImplementation:
428  GenObjCClass(D->getName(), GetExternalSourceContainer(D),
430  break;
431  case Decl::ObjCCategory: {
432  const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
433  const ObjCInterfaceDecl *ID = CD->getClassInterface();
434  if (!ID) {
435  // Handle invalid code where the @interface might not
436  // have been specified.
437  // FIXME: We should be able to generate this USR even if the
438  // @interface isn't available.
439  IgnoreResults = true;
440  return;
441  }
442  // Specially handle class extensions, which are anonymous categories.
443  // We want to mangle in the location to uniquely distinguish them.
444  if (CD->IsClassExtension()) {
445  Out << "objc(ext)" << ID->getName() << '@';
446  GenLoc(CD, /*IncludeOffset=*/true);
447  }
448  else
449  GenObjCCategory(ID->getName(), CD->getName(),
452 
453  break;
454  }
455  case Decl::ObjCCategoryImpl: {
456  const ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
457  const ObjCInterfaceDecl *ID = CD->getClassInterface();
458  if (!ID) {
459  // Handle invalid code where the @interface might not
460  // have been specified.
461  // FIXME: We should be able to generate this USR even if the
462  // @interface isn't available.
463  IgnoreResults = true;
464  return;
465  }
466  GenObjCCategory(ID->getName(), CD->getName(),
469  break;
470  }
471  case Decl::ObjCProtocol: {
472  const ObjCProtocolDecl *PD = cast<ObjCProtocolDecl>(D);
473  GenObjCProtocol(PD->getName(), GetExternalSourceContainer(PD));
474  break;
475  }
476  }
477 }
478 
479 void USRGenerator::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
480  // The USR for a property declared in a class extension or category is based
481  // on the ObjCInterfaceDecl, not the ObjCCategoryDecl.
482  if (const ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
483  VisitObjCContainerDecl(ID, getCategoryContext(D));
484  else
485  Visit(cast<Decl>(D->getDeclContext()));
486  GenObjCProperty(D->getName(), D->isClassProperty());
487 }
488 
489 void USRGenerator::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
490  if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
491  VisitObjCPropertyDecl(PD);
492  return;
493  }
494 
495  IgnoreResults = true;
496 }
497 
498 void USRGenerator::VisitTagDecl(const TagDecl *D) {
499  // Add the location of the tag decl to handle resolution across
500  // translation units.
501  if (!isa<EnumDecl>(D) &&
502  ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
503  return;
504 
505  GenExtSymbolContainer(D);
506 
507  D = D->getCanonicalDecl();
508  VisitDeclContext(D->getDeclContext());
509 
510  bool AlreadyStarted = false;
511  if (const CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) {
512  if (ClassTemplateDecl *ClassTmpl = CXXRecord->getDescribedClassTemplate()) {
513  AlreadyStarted = true;
514 
515  switch (D->getTagKind()) {
516  case TTK_Interface:
517  case TTK_Class:
518  case TTK_Struct: Out << "@ST"; break;
519  case TTK_Union: Out << "@UT"; break;
520  case TTK_Enum: llvm_unreachable("enum template");
521  }
522  VisitTemplateParameterList(ClassTmpl->getTemplateParameters());
523  } else if (const ClassTemplatePartialSpecializationDecl *PartialSpec
524  = dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) {
525  AlreadyStarted = true;
526 
527  switch (D->getTagKind()) {
528  case TTK_Interface:
529  case TTK_Class:
530  case TTK_Struct: Out << "@SP"; break;
531  case TTK_Union: Out << "@UP"; break;
532  case TTK_Enum: llvm_unreachable("enum partial specialization");
533  }
534  VisitTemplateParameterList(PartialSpec->getTemplateParameters());
535  }
536  }
537 
538  if (!AlreadyStarted) {
539  switch (D->getTagKind()) {
540  case TTK_Interface:
541  case TTK_Class:
542  case TTK_Struct: Out << "@S"; break;
543  case TTK_Union: Out << "@U"; break;
544  case TTK_Enum: Out << "@E"; break;
545  }
546  }
547 
548  Out << '@';
549  assert(Buf.size() > 0);
550  const unsigned off = Buf.size() - 1;
551 
552  if (EmitDeclName(D)) {
553  if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) {
554  Buf[off] = 'A';
555  Out << '@' << *TD;
556  } else {
557  if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
558  printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
559  } else {
560  Buf[off] = 'a';
561  if (auto *ED = dyn_cast<EnumDecl>(D)) {
562  // Distinguish USRs of anonymous enums by using their first
563  // enumerator.
564  auto enum_range = ED->enumerators();
565  if (enum_range.begin() != enum_range.end()) {
566  Out << '@' << **enum_range.begin();
567  }
568  }
569  }
570  }
571  }
572 
573  // For a class template specialization, mangle the template arguments.
574  if (const ClassTemplateSpecializationDecl *Spec
575  = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
576  const TemplateArgumentList &Args = Spec->getTemplateArgs();
577  Out << '>';
578  for (unsigned I = 0, N = Args.size(); I != N; ++I) {
579  Out << '#';
580  VisitTemplateArgument(Args.get(I));
581  }
582  }
583 }
584 
585 void USRGenerator::VisitTypedefDecl(const TypedefDecl *D) {
586  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
587  return;
588  const DeclContext *DC = D->getDeclContext();
589  if (const NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
590  Visit(DCN);
591  Out << "@T@";
592  Out << D->getName();
593 }
594 
595 void USRGenerator::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
596  GenLoc(D, /*IncludeOffset=*/true);
597 }
598 
599 void USRGenerator::GenExtSymbolContainer(const NamedDecl *D) {
600  StringRef Container = GetExternalSourceContainer(D);
601  if (!Container.empty())
602  Out << "@M@" << Container;
603 }
604 
605 bool USRGenerator::GenLoc(const Decl *D, bool IncludeOffset) {
606  if (generatedLoc)
607  return IgnoreResults;
608  generatedLoc = true;
609 
610  // Guard against null declarations in invalid code.
611  if (!D) {
612  IgnoreResults = true;
613  return true;
614  }
615 
616  // Use the location of canonical decl.
617  D = D->getCanonicalDecl();
618 
619  IgnoreResults =
620  IgnoreResults || printLoc(Out, D->getBeginLoc(),
621  Context->getSourceManager(), IncludeOffset);
622 
623  return IgnoreResults;
624 }
625 
626 static void printQualifier(llvm::raw_ostream &Out, ASTContext &Ctx, NestedNameSpecifier *NNS) {
627  // FIXME: Encode the qualifier, don't just print it.
628  PrintingPolicy PO(Ctx.getLangOpts());
629  PO.SuppressTagKeyword = true;
630  PO.SuppressUnwrittenScope = true;
631  PO.ConstantArraySizeAsWritten = false;
632  PO.AnonymousTagLocations = false;
633  NNS->print(Out, PO);
634 }
635 
636 void USRGenerator::VisitType(QualType T) {
637  // This method mangles in USR information for types. It can possibly
638  // just reuse the naming-mangling logic used by codegen, although the
639  // requirements for USRs might not be the same.
640  ASTContext &Ctx = *Context;
641 
642  do {
643  T = Ctx.getCanonicalType(T);
644  Qualifiers Q = T.getQualifiers();
645  unsigned qVal = 0;
646  if (Q.hasConst())
647  qVal |= 0x1;
648  if (Q.hasVolatile())
649  qVal |= 0x2;
650  if (Q.hasRestrict())
651  qVal |= 0x4;
652  if(qVal)
653  Out << ((char) ('0' + qVal));
654 
655  // Mangle in ObjC GC qualifiers?
656 
657  if (const PackExpansionType *Expansion = T->getAs<PackExpansionType>()) {
658  Out << 'P';
659  T = Expansion->getPattern();
660  }
661 
662  if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
663  switch (BT->getKind()) {
664  case BuiltinType::Void:
665  Out << 'v'; break;
666  case BuiltinType::Bool:
667  Out << 'b'; break;
668  case BuiltinType::UChar:
669  Out << 'c'; break;
670  case BuiltinType::Char8:
671  Out << 'u'; break;
672  case BuiltinType::Char16:
673  Out << 'q'; break;
674  case BuiltinType::Char32:
675  Out << 'w'; break;
676  case BuiltinType::UShort:
677  Out << 's'; break;
678  case BuiltinType::UInt:
679  Out << 'i'; break;
680  case BuiltinType::ULong:
681  Out << 'l'; break;
682  case BuiltinType::ULongLong:
683  Out << 'k'; break;
684  case BuiltinType::UInt128:
685  Out << 'j'; break;
686  case BuiltinType::Char_U:
687  case BuiltinType::Char_S:
688  Out << 'C'; break;
689  case BuiltinType::SChar:
690  Out << 'r'; break;
691  case BuiltinType::WChar_S:
692  case BuiltinType::WChar_U:
693  Out << 'W'; break;
694  case BuiltinType::Short:
695  Out << 'S'; break;
696  case BuiltinType::Int:
697  Out << 'I'; break;
698  case BuiltinType::Long:
699  Out << 'L'; break;
700  case BuiltinType::LongLong:
701  Out << 'K'; break;
702  case BuiltinType::Int128:
703  Out << 'J'; break;
704  case BuiltinType::Float16:
705  case BuiltinType::Half:
706  Out << 'h'; break;
707  case BuiltinType::Float:
708  Out << 'f'; break;
709  case BuiltinType::Double:
710  Out << 'd'; break;
711  case BuiltinType::LongDouble:
712  Out << 'D'; break;
713  case BuiltinType::Float128:
714  Out << 'Q'; break;
715  case BuiltinType::NullPtr:
716  Out << 'n'; break;
717 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
718  case BuiltinType::Id: \
719  Out << "@BT@" << #Suffix << "_" << #ImgType; break;
720 #include "clang/Basic/OpenCLImageTypes.def"
721 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
722  case BuiltinType::Id: \
723  Out << "@BT@" << #ExtType; break;
724 #include "clang/Basic/OpenCLExtensionTypes.def"
725  case BuiltinType::OCLEvent:
726  Out << "@BT@OCLEvent"; break;
727  case BuiltinType::OCLClkEvent:
728  Out << "@BT@OCLClkEvent"; break;
729  case BuiltinType::OCLQueue:
730  Out << "@BT@OCLQueue"; break;
731  case BuiltinType::OCLReserveID:
732  Out << "@BT@OCLReserveID"; break;
733  case BuiltinType::OCLSampler:
734  Out << "@BT@OCLSampler"; break;
735 #define SVE_TYPE(Name, Id, SingletonId) \
736  case BuiltinType::Id: \
737  Out << "@BT@" << Name; break;
738 #include "clang/Basic/AArch64SVEACLETypes.def"
739 #define PPC_VECTOR_TYPE(Name, Id, Size) \
740  case BuiltinType::Id: \
741  Out << "@BT@" << #Name; break;
742 #include "clang/Basic/PPCTypes.def"
743 #define RVV_TYPE(Name, Id, SingletonId) \
744  case BuiltinType::Id: \
745  Out << "@BT@" << Name; break;
746 #include "clang/Basic/RISCVVTypes.def"
747  case BuiltinType::ShortAccum:
748  Out << "@BT@ShortAccum"; break;
749  case BuiltinType::Accum:
750  Out << "@BT@Accum"; break;
751  case BuiltinType::LongAccum:
752  Out << "@BT@LongAccum"; break;
753  case BuiltinType::UShortAccum:
754  Out << "@BT@UShortAccum"; break;
755  case BuiltinType::UAccum:
756  Out << "@BT@UAccum"; break;
757  case BuiltinType::ULongAccum:
758  Out << "@BT@ULongAccum"; break;
759  case BuiltinType::ShortFract:
760  Out << "@BT@ShortFract"; break;
761  case BuiltinType::Fract:
762  Out << "@BT@Fract"; break;
763  case BuiltinType::LongFract:
764  Out << "@BT@LongFract"; break;
765  case BuiltinType::UShortFract:
766  Out << "@BT@UShortFract"; break;
767  case BuiltinType::UFract:
768  Out << "@BT@UFract"; break;
769  case BuiltinType::ULongFract:
770  Out << "@BT@ULongFract"; break;
771  case BuiltinType::SatShortAccum:
772  Out << "@BT@SatShortAccum"; break;
773  case BuiltinType::SatAccum:
774  Out << "@BT@SatAccum"; break;
775  case BuiltinType::SatLongAccum:
776  Out << "@BT@SatLongAccum"; break;
777  case BuiltinType::SatUShortAccum:
778  Out << "@BT@SatUShortAccum"; break;
779  case BuiltinType::SatUAccum:
780  Out << "@BT@SatUAccum"; break;
781  case BuiltinType::SatULongAccum:
782  Out << "@BT@SatULongAccum"; break;
783  case BuiltinType::SatShortFract:
784  Out << "@BT@SatShortFract"; break;
785  case BuiltinType::SatFract:
786  Out << "@BT@SatFract"; break;
787  case BuiltinType::SatLongFract:
788  Out << "@BT@SatLongFract"; break;
789  case BuiltinType::SatUShortFract:
790  Out << "@BT@SatUShortFract"; break;
791  case BuiltinType::SatUFract:
792  Out << "@BT@SatUFract"; break;
793  case BuiltinType::SatULongFract:
794  Out << "@BT@SatULongFract"; break;
795  case BuiltinType::BFloat16:
796  Out << "@BT@__bf16"; break;
797  case BuiltinType::Ibm128:
798  Out << "@BT@__ibm128"; break;
799  case BuiltinType::ObjCId:
800  Out << 'o'; break;
801  case BuiltinType::ObjCClass:
802  Out << 'O'; break;
803  case BuiltinType::ObjCSel:
804  Out << 'e'; break;
805 #define BUILTIN_TYPE(Id, SingletonId)
806 #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
807 #include "clang/AST/BuiltinTypes.def"
808  case BuiltinType::Dependent:
809  // If you're adding a new builtin type, please add its name prefixed
810  // with "@BT@" to `Out` (see cases above).
811  IgnoreResults = true;
812  break;
813  }
814  return;
815  }
816 
817  // If we have already seen this (non-built-in) type, use a substitution
818  // encoding.
819  llvm::DenseMap<const Type *, unsigned>::iterator Substitution
820  = TypeSubstitutions.find(T.getTypePtr());
821  if (Substitution != TypeSubstitutions.end()) {
822  Out << 'S' << Substitution->second << '_';
823  return;
824  } else {
825  // Record this as a substitution.
826  unsigned Number = TypeSubstitutions.size();
827  TypeSubstitutions[T.getTypePtr()] = Number;
828  }
829 
830  if (const PointerType *PT = T->getAs<PointerType>()) {
831  Out << '*';
832  T = PT->getPointeeType();
833  continue;
834  }
835  if (const ObjCObjectPointerType *OPT = T->getAs<ObjCObjectPointerType>()) {
836  Out << '*';
837  T = OPT->getPointeeType();
838  continue;
839  }
840  if (const RValueReferenceType *RT = T->getAs<RValueReferenceType>()) {
841  Out << "&&";
842  T = RT->getPointeeType();
843  continue;
844  }
845  if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
846  Out << '&';
847  T = RT->getPointeeType();
848  continue;
849  }
850  if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) {
851  Out << 'F';
852  VisitType(FT->getReturnType());
853  Out << '(';
854  for (const auto &I : FT->param_types()) {
855  Out << '#';
856  VisitType(I);
857  }
858  Out << ')';
859  if (FT->isVariadic())
860  Out << '.';
861  return;
862  }
863  if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) {
864  Out << 'B';
865  T = BT->getPointeeType();
866  continue;
867  }
868  if (const ComplexType *CT = T->getAs<ComplexType>()) {
869  Out << '<';
870  T = CT->getElementType();
871  continue;
872  }
873  if (const TagType *TT = T->getAs<TagType>()) {
874  Out << '$';
875  VisitTagDecl(TT->getDecl());
876  return;
877  }
878  if (const ObjCInterfaceType *OIT = T->getAs<ObjCInterfaceType>()) {
879  Out << '$';
880  VisitObjCInterfaceDecl(OIT->getDecl());
881  return;
882  }
883  if (const ObjCObjectType *OIT = T->getAs<ObjCObjectType>()) {
884  Out << 'Q';
885  VisitType(OIT->getBaseType());
886  for (auto *Prot : OIT->getProtocols())
887  VisitObjCProtocolDecl(Prot);
888  return;
889  }
890  if (const TemplateTypeParmType *TTP = T->getAs<TemplateTypeParmType>()) {
891  Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
892  return;
893  }
894  if (const TemplateSpecializationType *Spec
896  Out << '>';
897  VisitTemplateName(Spec->getTemplateName());
898  Out << Spec->template_arguments().size();
899  for (const auto &Arg : Spec->template_arguments())
900  VisitTemplateArgument(Arg);
901  return;
902  }
903  if (const DependentNameType *DNT = T->getAs<DependentNameType>()) {
904  Out << '^';
905  printQualifier(Out, Ctx, DNT->getQualifier());
906  Out << ':' << DNT->getIdentifier()->getName();
907  return;
908  }
909  if (const InjectedClassNameType *InjT = T->getAs<InjectedClassNameType>()) {
910  T = InjT->getInjectedSpecializationType();
911  continue;
912  }
913  if (const auto *VT = T->getAs<VectorType>()) {
914  Out << (T->isExtVectorType() ? ']' : '[');
915  Out << VT->getNumElements();
916  T = VT->getElementType();
917  continue;
918  }
919  if (const auto *const AT = dyn_cast<ArrayType>(T)) {
920  Out << '{';
921  switch (AT->getSizeModifier()) {
922  case ArrayType::Static:
923  Out << 's';
924  break;
925  case ArrayType::Star:
926  Out << '*';
927  break;
928  case ArrayType::Normal:
929  Out << 'n';
930  break;
931  }
932  if (const auto *const CAT = dyn_cast<ConstantArrayType>(T))
933  Out << CAT->getSize();
934 
935  T = AT->getElementType();
936  continue;
937  }
938 
939  // Unhandled type.
940  Out << ' ';
941  break;
942  } while (true);
943 }
944 
945 void USRGenerator::VisitTemplateParameterList(
946  const TemplateParameterList *Params) {
947  if (!Params)
948  return;
949  Out << '>' << Params->size();
950  for (TemplateParameterList::const_iterator P = Params->begin(),
951  PEnd = Params->end();
952  P != PEnd; ++P) {
953  Out << '#';
954  if (isa<TemplateTypeParmDecl>(*P)) {
955  if (cast<TemplateTypeParmDecl>(*P)->isParameterPack())
956  Out<< 'p';
957  Out << 'T';
958  continue;
959  }
960 
961  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
962  if (NTTP->isParameterPack())
963  Out << 'p';
964  Out << 'N';
965  VisitType(NTTP->getType());
966  continue;
967  }
968 
969  TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P);
970  if (TTP->isParameterPack())
971  Out << 'p';
972  Out << 't';
973  VisitTemplateParameterList(TTP->getTemplateParameters());
974  }
975 }
976 
977 void USRGenerator::VisitTemplateName(TemplateName Name) {
978  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
979  if (TemplateTemplateParmDecl *TTP
980  = dyn_cast<TemplateTemplateParmDecl>(Template)) {
981  Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
982  return;
983  }
984 
985  Visit(Template);
986  return;
987  }
988 
989  // FIXME: Visit dependent template names.
990 }
991 
992 void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) {
993  switch (Arg.getKind()) {
994  case TemplateArgument::Null:
995  break;
996 
997  case TemplateArgument::Declaration:
998  Visit(Arg.getAsDecl());
999  break;
1000 
1001  case TemplateArgument::NullPtr:
1002  break;
1003 
1004  case TemplateArgument::TemplateExpansion:
1005  Out << 'P'; // pack expansion of...
1006  [[fallthrough]];
1007  case TemplateArgument::Template:
1008  VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1009  break;
1010 
1011  case TemplateArgument::Expression:
1012  // FIXME: Visit expressions.
1013  break;
1014 
1015  case TemplateArgument::Pack:
1016  Out << 'p' << Arg.pack_size();
1017  for (const auto &P : Arg.pack_elements())
1018  VisitTemplateArgument(P);
1019  break;
1020 
1021  case TemplateArgument::Type:
1022  VisitType(Arg.getAsType());
1023  break;
1024 
1025  case TemplateArgument::Integral:
1026  Out << 'V';
1027  VisitType(Arg.getIntegralType());
1028  Out << Arg.getAsIntegral();
1029  break;
1030  }
1031 }
1032 
1033 void USRGenerator::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
1034  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
1035  return;
1036  VisitDeclContext(D->getDeclContext());
1037  Out << "@UUV@";
1038  printQualifier(Out, D->getASTContext(), D->getQualifier());
1039  EmitDeclName(D);
1040 }
1041 
1042 void USRGenerator::VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D) {
1043  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
1044  return;
1045  VisitDeclContext(D->getDeclContext());
1046  Out << "@UUT@";
1047  printQualifier(Out, D->getASTContext(), D->getQualifier());
1048  Out << D->getName(); // Simple name.
1049 }
1050 
1051 void USRGenerator::VisitConceptDecl(const ConceptDecl *D) {
1052  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
1053  return;
1054  VisitDeclContext(D->getDeclContext());
1055  Out << "@CT@";
1056  EmitDeclName(D);
1057 }
1058 
1059 void USRGenerator::VisitMSGuidDecl(const MSGuidDecl *D) {
1060  VisitDeclContext(D->getDeclContext());
1061  Out << "@MG@";
1062  D->NamedDecl::printName(Out);
1063 }
1064 
1065 //===----------------------------------------------------------------------===//
1066 // USR generation functions.
1067 //===----------------------------------------------------------------------===//
1068 
1069 static void combineClassAndCategoryExtContainers(StringRef ClsSymDefinedIn,
1070  StringRef CatSymDefinedIn,
1071  raw_ostream &OS) {
1072  if (ClsSymDefinedIn.empty() && CatSymDefinedIn.empty())
1073  return;
1074  if (CatSymDefinedIn.empty()) {
1075  OS << "@M@" << ClsSymDefinedIn << '@';
1076  return;
1077  }
1078  OS << "@CM@" << CatSymDefinedIn << '@';
1079  if (ClsSymDefinedIn != CatSymDefinedIn) {
1080  OS << ClsSymDefinedIn << '@';
1081  }
1082 }
1083 
1084 void clang::index::generateUSRForObjCClass(StringRef Cls, raw_ostream &OS,
1085  StringRef ExtSymDefinedIn,
1086  StringRef CategoryContextExtSymbolDefinedIn) {
1087  combineClassAndCategoryExtContainers(ExtSymDefinedIn,
1088  CategoryContextExtSymbolDefinedIn, OS);
1089  OS << "objc(cs)" << Cls;
1090 }
1091 
1092 void clang::index::generateUSRForObjCCategory(StringRef Cls, StringRef Cat,
1093  raw_ostream &OS,
1094  StringRef ClsSymDefinedIn,
1095  StringRef CatSymDefinedIn) {
1096  combineClassAndCategoryExtContainers(ClsSymDefinedIn, CatSymDefinedIn, OS);
1097  OS << "objc(cy)" << Cls << '@' << Cat;
1098 }
1099 
1100 void clang::index::generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS) {
1101  OS << '@' << Ivar;
1102 }
1103 
1104 void clang::index::generateUSRForObjCMethod(StringRef Sel,
1105  bool IsInstanceMethod,
1106  raw_ostream &OS) {
1107  OS << (IsInstanceMethod ? "(im)" : "(cm)") << Sel;
1108 }
1109 
1110 void clang::index::generateUSRForObjCProperty(StringRef Prop, bool isClassProp,
1111  raw_ostream &OS) {
1112  OS << (isClassProp ? "(cpy)" : "(py)") << Prop;
1113 }
1114 
1115 void clang::index::generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS,
1116  StringRef ExtSymDefinedIn) {
1117  if (!ExtSymDefinedIn.empty())
1118  OS << "@M@" << ExtSymDefinedIn << '@';
1119  OS << "objc(pl)" << Prot;
1120 }
1121 
1122 void clang::index::generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS,
1123  StringRef ExtSymDefinedIn) {
1124  if (!ExtSymDefinedIn.empty())
1125  OS << "@M@" << ExtSymDefinedIn;
1126  OS << "@E@" << EnumName;
1127 }
1128 
1129 void clang::index::generateUSRForEnumConstant(StringRef EnumConstantName,
1130  raw_ostream &OS) {
1131  OS << '@' << EnumConstantName;
1132 }
1133 
1134 bool clang::index::generateUSRForDecl(const Decl *D,
1135  SmallVectorImpl<char> &Buf) {
1136  if (!D)
1137  return true;
1138  // We don't ignore decls with invalid source locations. Implicit decls, like
1139  // C++'s operator new function, can have invalid locations but it is fine to
1140  // create USRs that can identify them.
1141 
1142  USRGenerator UG(&D->getASTContext(), Buf);
1143  UG.Visit(D);
1144  return UG.ignoreResults();
1145 }
1146 
1148  const SourceManager &SM,
1149  SmallVectorImpl<char> &Buf) {
1150  if (!MD)
1151  return true;
1152  return generateUSRForMacro(MD->getName()->getName(), MD->getLocation(),
1153  SM, Buf);
1154 
1155 }
1156 
1158  const SourceManager &SM,
1159  SmallVectorImpl<char> &Buf) {
1160  if (MacroName.empty())
1161  return true;
1162 
1163  llvm::raw_svector_ostream Out(Buf);
1164 
1165  // Assume that system headers are sane. Don't put source location
1166  // information into the USR if the macro comes from a system header.
1167  bool ShouldGenerateLocation = Loc.isValid() && !SM.isInSystemHeader(Loc);
1168 
1169  Out << getUSRSpacePrefix();
1170  if (ShouldGenerateLocation)
1171  printLoc(Out, Loc, SM, /*IncludeOffset=*/true);
1172  Out << "@macro@";
1173  Out << MacroName;
1174  return false;
1175 }
1176 
1178  SmallVectorImpl<char> &Buf) {
1179  if (T.isNull())
1180  return true;
1181  T = T.getCanonicalType();
1182 
1183  USRGenerator UG(&Ctx, Buf);
1184  UG.VisitType(T);
1185  return UG.ignoreResults();
1186 }
1187 
1189  raw_ostream &OS) {
1190  if (!Mod->Parent)
1191  return generateFullUSRForTopLevelModuleName(Mod->Name, OS);
1192  if (generateFullUSRForModule(Mod->Parent, OS))
1193  return true;
1194  return generateUSRFragmentForModule(Mod, OS);
1195 }
1196 
1198  raw_ostream &OS) {
1199  OS << getUSRSpacePrefix();
1200  return generateUSRFragmentForModuleName(ModName, OS);
1201 }
1202 
1204  raw_ostream &OS) {
1205  return generateUSRFragmentForModuleName(Mod->Name, OS);
1206 }
1207 
1209  raw_ostream &OS) {
1210  OS << "@M@" << ModName;
1211  return false;
1212 }
clang::BuiltinType
This class is used for builtin types like 'int'.
Definition: Type.h:2620
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1148
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:428
clang::LinkageSpecDecl
Represents a linkage specification.
Definition: DeclCXX.h:2832
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1389
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:560
clang::NamespaceAliasDecl
Represents a C++ namespace alias.
Definition: DeclCXX.h:3021
clang::TTK_Enum
@ TTK_Enum
The "enum" keyword.
Definition: Type.h:5547
clang::NamedDecl::isExternallyVisible
bool isExternallyVisible() const
Definition: Decl.h:407
clang::UsingDirectiveDecl
Represents C++ using-directive.
Definition: DeclCXX.h:2917
clang::BindingDecl
A binding in a decomposition declaration.
Definition: DeclCXX.h:4008
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::QualType::getQualifiers
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6662
clang::TTK_Struct
@ TTK_Struct
The "struct" keyword.
Definition: Type.h:5535
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::index::generateFullUSRForModule
bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS)
Generate a USR for a module, including the USR prefix.
Definition: USRGeneration.cpp:1188
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::ObjCPropertyDecl::isClassProperty
bool isClassProperty() const
Definition: DeclObjC.h:850
clang::NonTypeTemplateParmDecl
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Definition: DeclTemplate.h:1407
Attr.h
clang::QualType::getCanonicalType
QualType getCanonicalType() const
Definition: Type.h:6674
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2930
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::transformer::cat
Stencil cat(Ts &&... Parts)
Concatenates 0+ stencil pieces into a single stencil.
Definition: Stencil.h:64
clang::ObjCCategoryDecl::getClassInterface
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2338
clang::TagDecl::getCanonicalDecl
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:4413
clang::Module::Name
std::string Name
The name of this module.
Definition: Module.h:101
clang::TemplateSpecializationType
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5354
clang::ObjCPropertyImplDecl
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2770
clang::ObjCCategoryDecl::IsClassExtension
bool IsClassExtension() const
Definition: DeclObjC.h:2403
clang::TagDecl::isEmbeddedInDeclarator
bool isEmbeddedInDeclarator() const
True if this tag declaration is "embedded" (i.e., defined or declared for the very first time) in the...
Definition: Decl.h:3552
clang::TagType
Definition: Type.h:4792
clang::Decl::getParentFunctionOrMethod
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
Definition: DeclBase.cpp:295
clang::index::getUSRSpacePrefix
static StringRef getUSRSpacePrefix()
Definition: USRGeneration.h:26
clang::FunctionDecl::getTemplateSpecializationArgs
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3932
clang::TagDecl::getTypedefNameForAnonDecl
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3651
clang::ClassTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2098
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
print
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
Definition: InterpFrame.cpp:97
clang::VarTemplateSpecializationDecl
Represents a variable template specialization, which refers to a variable template with a given set o...
Definition: DeclTemplate.h:2687
clang::Qualifiers::hasConst
bool hasConst() const
Definition: Type.h:264
clang::TTK_Interface
@ TTK_Interface
The "__interface" keyword.
Definition: Type.h:5538
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:144
clang::ASTContext::getSourceManager
SourceManager & getSourceManager()
Definition: ASTContext.h:694
clang::ObjCImplDecl::getClassInterface
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2453
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:637
clang::ObjCObjectType
Represents a class type in Objective C.
Definition: Type.h:6014
clang::index::generateUSRForObjCProperty
void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS)
Generate a USR fragment for an Objective-C property.
Definition: USRGeneration.cpp:1110
clang::UnresolvedUsingTypenameDecl
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3858
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:1006
V
#define V(N, I)
Definition: ASTContext.h:3208
clang::ast_matchers::attr
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
Definition: ASTMatchersInternal.cpp:1032
clang::Module
Describes a module or submodule.
Definition: Module.h:98
DeclTemplate.h
clang::index::generateFullUSRForTopLevelModuleName
bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS)
Generate a USR for a top-level module name, including the USR prefix.
Definition: USRGeneration.cpp:1197
clang::PackExpansionType
Represents a pack expansion of types.
Definition: Type.h:5830
clang::Qualifiers::hasRestrict
bool hasRestrict() const
Definition: Type.h:284
clang::Decl::getKind
Kind getKind() const
Definition: DeclBase.h:435
clang::ConceptDecl
Declaration of a C++20 concept.
Definition: DeclTemplate.h:3259
clang::index::SymbolRole::Implicit
@ Implicit
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::TemplateArgument
Represents a template argument.
Definition: TemplateBase.h:61
GetExternalSourceContainer
static StringRef GetExternalSourceContainer(const NamedDecl *D)
Definition: USRGeneration.cpp:50
clang::RISCV::Policy
Policy
Definition: RISCVVIntrinsicUtils.h:96
clang::MSGuidDecl
A global _GUID constant.
Definition: DeclCXX.h:4188
clang::MacroDefinitionRecord
Record the location of a macro definition.
Definition: PreprocessingRecord.h:147
clang::TemplateTemplateParmDecl
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Definition: DeclTemplate.h:1624
ASTContext.h
clang::index::generateUSRForObjCProtocol
void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS, StringRef ExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C protocol.
Definition: USRGeneration.cpp:1115
clang::ASTContext::getObjContainingInterface
const ObjCInterfaceDecl * getObjContainingInterface(const NamedDecl *ND) const
Returns the Objective-C interface that ND belongs to if it is an Objective-C method/property/ivar etc...
Definition: ASTContext.cpp:2984
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::CodeGen::BlockCaptureEntityKind::CXXRecord
@ CXXRecord
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:625
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3423
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:70
clang::TTK_Class
@ TTK_Class
The "class" keyword.
Definition: Type.h:5544
clang::ObjCCategoryImplDecl
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2512
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2501
clang::TTK_Union
@ TTK_Union
The "union" keyword.
Definition: Type.h:5541
printLoc
static bool printLoc(llvm::raw_ostream &OS, SourceLocation Loc, const SourceManager &SM, bool IncludeOffset)
Definition: USRGeneration.cpp:27
clang::UnresolvedUsingValueDecl
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3762
clang::BlockPointerType
Pointer to a block type.
Definition: Type.h:2849
clang::TemplateTypeParmDecl
Declaration of a template type parameter.
Definition: DeclTemplate.h:1205
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:366
clang::index::generateUSRFragmentForModule
bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS)
Generate a USR fragment for a module.
Definition: USRGeneration.cpp:1203
clang::UsingDecl
Represents a C++ using-declaration.
Definition: DeclCXX.h:3414
clang::Module::Parent
Module * Parent
The parent of this module.
Definition: Module.h:135
clang::ObjCCategoryDecl
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2293
clang::VarDecl::getDescribedVarTemplate
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2703
clang::TemplateTypeParmType
Definition: Type.h:5002
clang::index
Definition: CommentToXML.h:22
clang::ObjCObjectPointerType
Represents a pointer to an Objective C object.
Definition: Type.h:6270
clang::MacroDefinitionRecord::getLocation
SourceLocation getLocation() const
Retrieve the location of the macro name in the definition.
Definition: PreprocessingRecord.h:160
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
false
#define false
Definition: stdbool.h:22
clang::TagDecl::isFreeStanding
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
Definition: Decl.h:3563
clang::ClassTemplateDecl
Declaration of a class template.
Definition: DeclTemplate.h:2270
clang::ComplexType
Complex values, per C99 6.2.5p11.
Definition: Type.h:2716
clang::ConstDeclVisitor
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:73
clang::TemplateName
Represents a C++ template name within the type system.
Definition: TemplateName.h:201
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4016
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1923
clang::VarTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2949
PreprocessingRecord.h
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:802
DeclVisitor.h
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::ObjCPropertyDecl
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:731
clang::index::generateUSRFragmentForModuleName
bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS)
Generate a USR fragment for a module name.
Definition: USRGeneration.cpp:1208
USRGeneration.h
clang::RISCV::Float
@ Float
Definition: RISCVVIntrinsicUtils.h:170
clang::Decl::getExternalSourceSymbolAttr
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
Definition: DeclBase.cpp:494
getCategoryContext
static const ObjCCategoryDecl * getCategoryContext(const NamedDecl *D)
Definition: USRGeneration.cpp:390
clang::Qualifiers::hasVolatile
bool hasVolatile() const
Definition: Type.h:274
clang::TemplateArgumentList
A template argument list.
Definition: DeclTemplate.h:238
clang::TypedefDecl
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3377
clang::ObjCPropertyImplDecl::getPropertyDecl
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2834
clang::FunctionDecl::isExternC
bool isExternC() const
Determines whether this function is a function with external, C linkage.
Definition: Decl.cpp:3303
clang::RValueReferenceType
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2942
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2769
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:196
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::index::generateUSRForObjCClass
void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS, StringRef ExtSymbolDefinedIn="", StringRef CategoryContextExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C class.
Definition: USRGeneration.cpp:1084
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang
Definition: CalledOnceCheck.h:17
clang::DeclarationName::print
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Definition: DeclarationName.cpp:138
clang::FileEntry::getName
StringRef getName() const
Definition: FileEntry.h:397
clang::ObjCProtocolDecl
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2049
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
s
__device__ __2f16 float bool s
Definition: __clang_hip_libdevice_declares.h:320
clang::TagDecl::getTagKind
TagKind getTagKind() const
Definition: Decl.h:3620
clang::TypedefNameDecl
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3275
clang::ObjCContainerDecl
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:943
clang::index::generateUSRForMacro
bool generateUSRForMacro(const MacroDefinitionRecord *MD, const SourceManager &SM, SmallVectorImpl< char > &Buf)
Generate a USR for a macro, including the USR prefix.
Definition: USRGeneration.cpp:1147
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6622
clang::index::generateUSRForObjCCategory
void generateUSRForObjCCategory(StringRef Cls, StringRef Cat, raw_ostream &OS, StringRef ClsExtSymbolDefinedIn="", StringRef CatExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C class category.
Definition: USRGeneration.cpp:1092
clang::ReferenceType
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2880
clang::MacroDefinitionRecord::getName
const IdentifierInfo * getName() const
Retrieve the name of the macro being defined.
Definition: PreprocessingRecord.h:157
llvm::SmallVectorImpl< char >
FileManager.h
clang::DeclarationName::isEmpty
bool isEmpty() const
Evaluates true when this declaration name is empty.
Definition: DeclarationName.h:381
clang::VarTemplateDecl
Declaration of a variable template.
Definition: DeclTemplate.h:3103
clang::FunctionDecl::getDescribedFunctionTemplate
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3802
SM
#define SM(sm)
Definition: Cuda.cpp:79
clang::ClassTemplateSpecializationDecl
Represents a class template specialization, which refers to a class template with a given set of temp...
Definition: DeclTemplate.h:1826
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:432
clang::NamespaceDecl
Represent a C++ namespace.
Definition: Decl.h:542
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1904
clang::index::generateUSRForType
bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl< char > &Buf)
Generates a USR for a type.
Definition: USRGeneration.cpp:1177
clang::ObjCInterfaceType
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6214
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:764
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:441
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274