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