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