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.AnonymousTagNameStyle =
670 llvm::to_underlying(PrintingPolicy::AnonymousTagMode::Plain);
671 NNS.print(Out, PO);
672}
673
674void USRGenerator::VisitType(QualType T) {
675 // This method mangles in USR information for types. It can possibly
676 // just reuse the naming-mangling logic used by codegen, although the
677 // requirements for USRs might not be the same.
678 ASTContext &Ctx = *Context;
679
680 do {
681 T = Ctx.getCanonicalType(T);
682 Qualifiers Q = T.getQualifiers();
683 unsigned qVal = 0;
684 if (Q.hasConst())
685 qVal |= 0x1;
686 if (Q.hasVolatile())
687 qVal |= 0x2;
688 if (Q.hasRestrict())
689 qVal |= 0x4;
690 if(qVal)
691 Out << ((char) ('0' + qVal));
692
693 // Mangle in ObjC GC qualifiers?
694
695 if (const PackExpansionType *Expansion = T->getAs<PackExpansionType>()) {
696 Out << 'P';
697 T = Expansion->getPattern();
698 }
699
700 if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
701 switch (BT->getKind()) {
702 case BuiltinType::Void:
703 Out << 'v'; break;
704 case BuiltinType::Bool:
705 Out << 'b'; break;
706 case BuiltinType::UChar:
707 Out << 'c'; break;
708 case BuiltinType::Char8:
709 Out << 'u'; break;
710 case BuiltinType::Char16:
711 Out << 'q'; break;
712 case BuiltinType::Char32:
713 Out << 'w'; break;
714 case BuiltinType::UShort:
715 Out << 's'; break;
716 case BuiltinType::UInt:
717 Out << 'i'; break;
718 case BuiltinType::ULong:
719 Out << 'l'; break;
720 case BuiltinType::ULongLong:
721 Out << 'k'; break;
722 case BuiltinType::UInt128:
723 Out << 'j'; break;
724 case BuiltinType::Char_U:
725 case BuiltinType::Char_S:
726 Out << 'C'; break;
727 case BuiltinType::SChar:
728 Out << 'r'; break;
729 case BuiltinType::WChar_S:
730 case BuiltinType::WChar_U:
731 Out << 'W'; break;
732 case BuiltinType::Short:
733 Out << 'S'; break;
734 case BuiltinType::Int:
735 Out << 'I'; break;
736 case BuiltinType::Long:
737 Out << 'L'; break;
738 case BuiltinType::LongLong:
739 Out << 'K'; break;
740 case BuiltinType::Int128:
741 Out << 'J'; break;
742 case BuiltinType::Float16:
743 case BuiltinType::Half:
744 Out << 'h'; break;
745 case BuiltinType::Float:
746 Out << 'f'; break;
747 case BuiltinType::Double:
748 Out << 'd'; break;
749 case BuiltinType::LongDouble:
750 Out << 'D'; break;
751 case BuiltinType::Float128:
752 Out << 'Q'; break;
753 case BuiltinType::NullPtr:
754 Out << 'n'; break;
755#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
756 case BuiltinType::Id: \
757 Out << "@BT@" << #Suffix << "_" << #ImgType; break;
758#include "clang/Basic/OpenCLImageTypes.def"
759#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
760 case BuiltinType::Id: \
761 Out << "@BT@" << #ExtType; break;
762#include "clang/Basic/OpenCLExtensionTypes.def"
763 case BuiltinType::OCLEvent:
764 Out << "@BT@OCLEvent"; break;
765 case BuiltinType::OCLClkEvent:
766 Out << "@BT@OCLClkEvent"; break;
767 case BuiltinType::OCLQueue:
768 Out << "@BT@OCLQueue"; break;
769 case BuiltinType::OCLReserveID:
770 Out << "@BT@OCLReserveID"; break;
771 case BuiltinType::OCLSampler:
772 Out << "@BT@OCLSampler"; break;
773#define SVE_TYPE(Name, Id, SingletonId) \
774 case BuiltinType::Id: \
775 Out << "@BT@" << #Name; \
776 break;
777#include "clang/Basic/AArch64ACLETypes.def"
778#define PPC_VECTOR_TYPE(Name, Id, Size) \
779 case BuiltinType::Id: \
780 Out << "@BT@" << #Name; break;
781#include "clang/Basic/PPCTypes.def"
782#define RVV_TYPE(Name, Id, SingletonId) \
783 case BuiltinType::Id: \
784 Out << "@BT@" << Name; break;
785#include "clang/Basic/RISCVVTypes.def"
786#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
787#include "clang/Basic/WebAssemblyReferenceTypes.def"
788#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
789 case BuiltinType::Id: \
790 Out << "@BT@" << #Name; \
791 break;
792#include "clang/Basic/AMDGPUTypes.def"
793#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
794 case BuiltinType::Id: \
795 Out << "@BT@" << #Name; \
796 break;
797#include "clang/Basic/HLSLIntangibleTypes.def"
798 case BuiltinType::ShortAccum:
799 Out << "@BT@ShortAccum"; break;
800 case BuiltinType::Accum:
801 Out << "@BT@Accum"; break;
802 case BuiltinType::LongAccum:
803 Out << "@BT@LongAccum"; break;
804 case BuiltinType::UShortAccum:
805 Out << "@BT@UShortAccum"; break;
806 case BuiltinType::UAccum:
807 Out << "@BT@UAccum"; break;
808 case BuiltinType::ULongAccum:
809 Out << "@BT@ULongAccum"; break;
810 case BuiltinType::ShortFract:
811 Out << "@BT@ShortFract"; break;
812 case BuiltinType::Fract:
813 Out << "@BT@Fract"; break;
814 case BuiltinType::LongFract:
815 Out << "@BT@LongFract"; break;
816 case BuiltinType::UShortFract:
817 Out << "@BT@UShortFract"; break;
818 case BuiltinType::UFract:
819 Out << "@BT@UFract"; break;
820 case BuiltinType::ULongFract:
821 Out << "@BT@ULongFract"; break;
822 case BuiltinType::SatShortAccum:
823 Out << "@BT@SatShortAccum"; break;
824 case BuiltinType::SatAccum:
825 Out << "@BT@SatAccum"; break;
826 case BuiltinType::SatLongAccum:
827 Out << "@BT@SatLongAccum"; break;
828 case BuiltinType::SatUShortAccum:
829 Out << "@BT@SatUShortAccum"; break;
830 case BuiltinType::SatUAccum:
831 Out << "@BT@SatUAccum"; break;
832 case BuiltinType::SatULongAccum:
833 Out << "@BT@SatULongAccum"; break;
834 case BuiltinType::SatShortFract:
835 Out << "@BT@SatShortFract"; break;
836 case BuiltinType::SatFract:
837 Out << "@BT@SatFract"; break;
838 case BuiltinType::SatLongFract:
839 Out << "@BT@SatLongFract"; break;
840 case BuiltinType::SatUShortFract:
841 Out << "@BT@SatUShortFract"; break;
842 case BuiltinType::SatUFract:
843 Out << "@BT@SatUFract"; break;
844 case BuiltinType::SatULongFract:
845 Out << "@BT@SatULongFract"; break;
846 case BuiltinType::BFloat16:
847 Out << "@BT@__bf16"; break;
848 case BuiltinType::Ibm128:
849 Out << "@BT@__ibm128"; break;
850 case BuiltinType::ObjCId:
851 Out << 'o'; break;
852 case BuiltinType::ObjCClass:
853 Out << 'O'; break;
854 case BuiltinType::ObjCSel:
855 Out << 'e'; break;
856#define BUILTIN_TYPE(Id, SingletonId)
857#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
858#include "clang/AST/BuiltinTypes.def"
859 case BuiltinType::Dependent:
860 // If you're adding a new builtin type, please add its name prefixed
861 // with "@BT@" to `Out` (see cases above).
862 IgnoreResults = true;
863 break;
864 }
865 return;
866 }
867
868 // If we have already seen this (non-built-in) type, use a substitution
869 // encoding. Otherwise, record this as a substitution.
870 auto [Substitution, Inserted] =
871 TypeSubstitutions.try_emplace(T.getTypePtr(), TypeSubstitutions.size());
872 if (!Inserted) {
873 Out << 'S' << Substitution->second << '_';
874 return;
875 }
876
877 if (const MemberPointerType *MPT = T->getAs<MemberPointerType>()) {
878 Out << "*M";
879 T = MPT->getPointeeType();
880 continue;
881 }
882 if (const PointerType *PT = T->getAs<PointerType>()) {
883 Out << '*';
884 T = PT->getPointeeType();
885 continue;
886 }
887 if (const ObjCObjectPointerType *OPT = T->getAs<ObjCObjectPointerType>()) {
888 Out << '*';
889 T = OPT->getPointeeType();
890 continue;
891 }
892 if (const RValueReferenceType *RT = T->getAs<RValueReferenceType>()) {
893 Out << "&&";
894 T = RT->getPointeeType();
895 continue;
896 }
897 if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
898 Out << '&';
899 T = RT->getPointeeType();
900 continue;
901 }
902 if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) {
903 Out << 'F';
904 VisitType(FT->getReturnType());
905 Out << '(';
906 for (const auto &I : FT->param_types()) {
907 Out << '#';
908 VisitType(I);
909 }
910 Out << ')';
911 if (FT->isVariadic())
912 Out << '.';
913
914 clang::RefQualifierKind rq = FT->getRefQualifier();
915
916 switch (rq) {
917 case clang::RQ_None:
918 // No ref-qualifier
919 break;
920 case clang::RQ_LValue:
921 Out << "&&";
922 break;
923 case clang::RQ_RValue:
924 Out << '&';
925 break;
926 }
927
928 return;
929 }
930 if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) {
931 Out << 'B';
932 T = BT->getPointeeType();
933 continue;
934 }
935 if (const ComplexType *CT = T->getAs<ComplexType>()) {
936 Out << '<';
937 T = CT->getElementType();
938 continue;
939 }
940 if (const TagType *TT = T->getAs<TagType>()) {
941 if (const auto *ICNT = dyn_cast<InjectedClassNameType>(TT)) {
942 T = ICNT->getDecl()->getCanonicalTemplateSpecializationType(Ctx);
943 } else {
944 Out << '$';
945 VisitTagDecl(TT->getDecl());
946 return;
947 }
948 }
949 if (const ObjCInterfaceType *OIT = T->getAs<ObjCInterfaceType>()) {
950 Out << '$';
951 VisitObjCInterfaceDecl(OIT->getDecl());
952 return;
953 }
954 if (const ObjCObjectType *OIT = T->getAs<ObjCObjectType>()) {
955 Out << 'Q';
956 VisitType(OIT->getBaseType());
957 for (auto *Prot : OIT->getProtocols())
958 VisitObjCProtocolDecl(Prot);
959 return;
960 }
961 if (const TemplateTypeParmType *TTP =
962 T->getAsCanonical<TemplateTypeParmType>()) {
963 Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
964 return;
965 }
966 if (const TemplateSpecializationType *Spec
967 = T->getAs<TemplateSpecializationType>()) {
968 Out << '>';
969 VisitTemplateName(Spec->getTemplateName());
970 Out << Spec->template_arguments().size();
971 for (const auto &Arg : Spec->template_arguments())
972 VisitTemplateArgument(Arg);
973 return;
974 }
975 if (const DependentNameType *DNT = T->getAs<DependentNameType>()) {
976 Out << '^';
977 printQualifier(Out, LangOpts, DNT->getQualifier());
978 Out << ':' << DNT->getIdentifier()->getName();
979 return;
980 }
981 if (const auto *VT = T->getAs<VectorType>()) {
982 Out << (T->isExtVectorType() ? ']' : '[');
983 Out << VT->getNumElements();
984 T = VT->getElementType();
985 continue;
986 }
987 if (const auto *const AT = dyn_cast<ArrayType>(T)) {
988 Out << '{';
989 switch (AT->getSizeModifier()) {
990 case ArraySizeModifier::Static:
991 Out << 's';
992 break;
993 case ArraySizeModifier::Star:
994 Out << '*';
995 break;
996 case ArraySizeModifier::Normal:
997 Out << 'n';
998 break;
999 }
1000 if (const auto *const CAT = dyn_cast<ConstantArrayType>(T))
1001 Out << CAT->getSize();
1002
1003 T = AT->getElementType();
1004 continue;
1005 }
1006
1007 // Unhandled type.
1008 Out << ' ';
1009 break;
1010 } while (true);
1011}
1012
1013void USRGenerator::VisitTemplateParameterList(
1014 const TemplateParameterList *Params) {
1015 if (!Params)
1016 return;
1017 Out << '>' << Params->size();
1018 for (TemplateParameterList::const_iterator P = Params->begin(),
1019 PEnd = Params->end();
1020 P != PEnd; ++P) {
1021 Out << '#';
1022 if (isa<TemplateTypeParmDecl>(*P)) {
1023 if (cast<TemplateTypeParmDecl>(*P)->isParameterPack())
1024 Out<< 'p';
1025 Out << 'T';
1026 continue;
1027 }
1028
1029 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
1030 if (NTTP->isParameterPack())
1031 Out << 'p';
1032 Out << 'N';
1033 VisitType(NTTP->getType());
1034 continue;
1035 }
1036
1037 TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P);
1038 if (TTP->isParameterPack())
1039 Out << 'p';
1040 Out << 't';
1041 VisitTemplateParameterList(TTP->getTemplateParameters());
1042 }
1043}
1044
1045void USRGenerator::VisitTemplateName(TemplateName Name) {
1046 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
1047 if (TemplateTemplateParmDecl *TTP
1048 = dyn_cast<TemplateTemplateParmDecl>(Template)) {
1049 Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
1050 return;
1051 }
1052
1053 Visit(Template);
1054 return;
1055 }
1056
1057 // FIXME: Visit dependent template names.
1058}
1059
1060void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) {
1061 switch (Arg.getKind()) {
1062 case TemplateArgument::Null:
1063 break;
1064
1065 case TemplateArgument::Declaration:
1066 Visit(Arg.getAsDecl());
1067 break;
1068
1069 case TemplateArgument::NullPtr:
1070 break;
1071
1072 case TemplateArgument::TemplateExpansion:
1073 Out << 'P'; // pack expansion of...
1074 [[fallthrough]];
1075 case TemplateArgument::Template:
1076 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1077 break;
1078
1079 case TemplateArgument::Expression:
1080 // FIXME: Visit expressions.
1081 break;
1082
1083 case TemplateArgument::Pack:
1084 Out << 'p' << Arg.pack_size();
1085 for (const auto &P : Arg.pack_elements())
1086 VisitTemplateArgument(P);
1087 break;
1088
1089 case TemplateArgument::Type:
1090 VisitType(Arg.getAsType());
1091 break;
1092
1093 case TemplateArgument::Integral:
1094 Out << 'V';
1095 VisitType(Arg.getIntegralType());
1096 Out << Arg.getAsIntegral();
1097 break;
1098
1099 case TemplateArgument::StructuralValue: {
1100 Out << 'S';
1101 VisitType(Arg.getStructuralValueType());
1102 ODRHash Hash{};
1103 Hash.AddStructuralValue(Arg.getAsStructuralValue());
1104 Out << Hash.CalculateHash();
1105 break;
1106 }
1107 }
1108}
1109
1110void USRGenerator::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
1111 if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
1112 return;
1113 VisitDeclContext(D->getDeclContext());
1114 Out << "@UUV@";
1115 printQualifier(Out, LangOpts, D->getQualifier());
1116 EmitDeclName(D);
1117}
1118
1119void USRGenerator::VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D) {
1120 if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
1121 return;
1122 VisitDeclContext(D->getDeclContext());
1123 Out << "@UUT@";
1124 printQualifier(Out, LangOpts, D->getQualifier());
1125 Out << D->getName(); // Simple name.
1126}
1127
1128void USRGenerator::VisitConceptDecl(const ConceptDecl *D) {
1129 if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
1130 return;
1131 VisitDeclContext(D->getDeclContext());
1132 Out << "@CT@";
1133 EmitDeclName(D);
1134}
1135
1136void USRGenerator::VisitMSGuidDecl(const MSGuidDecl *D) {
1137 VisitDeclContext(D->getDeclContext());
1138 Out << "@MG@";
1139 D->NamedDecl::printName(Out);
1140}
1141
1142//===----------------------------------------------------------------------===//
1143// USR generation functions.
1144//===----------------------------------------------------------------------===//
1145
1146static void combineClassAndCategoryExtContainers(StringRef ClsSymDefinedIn,
1147 StringRef CatSymDefinedIn,
1148 raw_ostream &OS) {
1149 if (ClsSymDefinedIn.empty() && CatSymDefinedIn.empty())
1150 return;
1151 if (CatSymDefinedIn.empty()) {
1152 OS << "@M@" << ClsSymDefinedIn << '@';
1153 return;
1154 }
1155 OS << "@CM@" << CatSymDefinedIn << '@';
1156 if (ClsSymDefinedIn != CatSymDefinedIn) {
1157 OS << ClsSymDefinedIn << '@';
1158 }
1159}
1160
1161void common::index::generateUSRForObjCClass(StringRef Cls, raw_ostream &OS,
1162 StringRef ExtSymDefinedIn,
1163 StringRef CategoryContextExtSymbolDefinedIn) {
1165 CategoryContextExtSymbolDefinedIn, OS);
1166 OS << "objc(cs)" << Cls;
1167}
1168
1169void common::index::generateUSRForObjCCategory(StringRef Cls, StringRef Cat,
1170 raw_ostream &OS,
1171 StringRef ClsSymDefinedIn,
1172 StringRef CatSymDefinedIn) {
1173 combineClassAndCategoryExtContainers(ClsSymDefinedIn, CatSymDefinedIn, OS);
1174 OS << "objc(cy)" << Cls << '@' << Cat;
1175}
1176
1177void common::index::generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS) {
1178 OS << '@' << Ivar;
1179}
1180
1182 bool IsInstanceMethod,
1183 raw_ostream &OS) {
1184 OS << (IsInstanceMethod ? "(im)" : "(cm)") << Sel;
1185}
1186
1187void common::index::generateUSRForObjCProperty(StringRef Prop, bool isClassProp,
1188 raw_ostream &OS) {
1189 OS << (isClassProp ? "(cpy)" : "(py)") << Prop;
1190}
1191
1192void common::index::generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS,
1193 StringRef ExtSymDefinedIn) {
1194 if (!ExtSymDefinedIn.empty())
1195 OS << "@M@" << ExtSymDefinedIn << '@';
1196 OS << "objc(pl)" << Prot;
1197}
1198
1199void common::index::generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS,
1200 StringRef ExtSymDefinedIn) {
1201 if (!ExtSymDefinedIn.empty())
1202 OS << "@M@" << ExtSymDefinedIn;
1203 OS << "@E@" << EnumName;
1204}
1205
1206void common::index::generateUSRForEnumConstant(StringRef EnumConstantName,
1207 raw_ostream &OS) {
1208 OS << '@' << EnumConstantName;
1209}
1210
1211bool common::index::generateUSRForDecl(const Decl *D,
1212 SmallVectorImpl<char> &Buf) {
1213 if (!D)
1214 return true;
1215 return generateUSRForDecl(D, Buf, D->getASTContext().getLangOpts());
1216}
1217
1218bool common::index::generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf,
1219 const LangOptions &LangOpts) {
1220 if (!D)
1221 return true;
1222 // We don't ignore decls with invalid source locations. Implicit decls, like
1223 // C++'s operator new function, can have invalid locations but it is fine to
1224 // create USRs that can identify them.
1225
1226 // Check if the declaration has explicit external USR specified.
1227 auto *CD = D->getCanonicalDecl();
1228 if (auto *ExternalSymAttr = CD->getAttr<ExternalSourceSymbolAttr>()) {
1229 if (!ExternalSymAttr->getUSR().empty()) {
1230 llvm::raw_svector_ostream Out(Buf);
1231 Out << ExternalSymAttr->getUSR();
1232 return false;
1233 }
1234 }
1235 USRGenerator UG(&D->getASTContext(), Buf, LangOpts);
1236 UG.Visit(D);
1237 return UG.ignoreResults();
1238}
1239
1240bool common::index::generateUSRForMacro(const MacroDefinitionRecord *MD,
1241 const SourceManager &SM,
1242 SmallVectorImpl<char> &Buf) {
1243 if (!MD)
1244 return true;
1245 return generateUSRForMacro(MD->getName()->getName(), MD->getLocation(),
1246 SM, Buf);
1247
1248}
1249
1250bool common::index::generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
1251 const SourceManager &SM,
1252 SmallVectorImpl<char> &Buf) {
1253 if (MacroName.empty())
1254 return true;
1255
1256 llvm::raw_svector_ostream Out(Buf);
1257
1258 // Assume that system headers are sane. Don't put source location
1259 // information into the USR if the macro comes from a system header.
1260 bool ShouldGenerateLocation = Loc.isValid() && !SM.isInSystemHeader(Loc);
1261
1262 Out << getUSRSpacePrefix();
1263 if (ShouldGenerateLocation)
1264 printLoc(Out, Loc, SM, /*IncludeOffset=*/true);
1265 Out << "@macro@";
1266 Out << MacroName;
1267 return false;
1268}
1269
1270bool common::index::generateUSRForType(QualType T, ASTContext &Ctx,
1271 SmallVectorImpl<char> &Buf) {
1272 return generateUSRForType(T, Ctx, Buf, Ctx.getLangOpts());
1273}
1274
1275bool common::index::generateUSRForType(QualType T, ASTContext &Ctx,
1276 SmallVectorImpl<char> &Buf,
1277 const LangOptions &LangOpts) {
1278 if (T.isNull())
1279 return true;
1280 T = T.getCanonicalType();
1281
1282 USRGenerator UG(&Ctx, Buf, LangOpts);
1283 UG.VisitType(T);
1284 return UG.ignoreResults();
1285}
1286
1287bool common::index::generateFullUSRForModule(const Module *Mod,
1288 raw_ostream &OS) {
1289 if (!Mod->Parent)
1290 return generateFullUSRForTopLevelModuleName(Mod->Name, OS);
1291 if (generateFullUSRForModule(Mod->Parent, OS))
1292 return true;
1293 return generateUSRFragmentForModule(Mod, OS);
1294}
1295
1297 raw_ostream &OS) {
1298 OS << getUSRSpacePrefix();
1299 return generateUSRFragmentForModuleName(ModName, OS);
1300}
1301
1302bool common::index::generateUSRFragmentForModule(const Module *Mod,
1303 raw_ostream &OS) {
1304 return generateUSRFragmentForModuleName(Mod->Name, OS);
1305}
1306
1308 raw_ostream &OS) {
1309 OS << "@M@" << ModName;
1310 return false;
1311}
1312
1313} // namespace clanguml