clang: lib/Index/USRGeneration.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
18#include "llvm/Support/Path.h"
19#include "llvm/Support/raw_ostream.h"
20
21using namespace clang;
23
24
25
26
27
28
32 return true;
33 }
34 Loc = SM.getExpansionLoc(Loc);
35 const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(Loc);
37 if (FE) {
38 OS << llvm::sys::path::filename(FE->getName());
39 } else {
40
41 return true;
42 }
43 if (IncludeOffset) {
44
45
46
47 OS << '@' << Decomposed.second;
48 }
49 return false;
50}
51
53 if ()
54 return StringRef();
56 return attr->getDefinedIn();
57 }
58 return StringRef();
59}
60
61namespace {
64 llvm::raw_svector_ostream Out;
67 bool IgnoreResults = false;
68 bool generatedLoc = false;
69
70 llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
71
72public:
75 : Buf(Buf), Out(Buf), Context(Ctx), LangOpts(LangOpts) {
76
78 }
79
80 bool ignoreResults() const { return IgnoreResults; }
81
82
84 void VisitFieldDecl(const FieldDecl *D);
86 void VisitNamedDecl(const NamedDecl *D);
96 void VisitTagDecl(const TagDecl *D);
99 void VisitVarDecl(const VarDecl *D);
106
108 IgnoreResults = true;
109 }
110
112 IgnoreResults = true;
113 }
114
115 void VisitUsingDecl(const UsingDecl *D) {
117 Out << "@UD@";
118
119 bool EmittedDeclName = !EmitDeclName(D);
120 assert(EmittedDeclName && "EmitDeclName can not fail for UsingDecls");
121 (void)EmittedDeclName;
122 }
123
124 bool ShouldGenerateLocation(const NamedDecl *D);
125
128 }
129
130 void GenExtSymbolContainer(const NamedDecl *D);
131
132
133
134 bool GenLoc(const Decl *D, bool IncludeOffset);
135
136
137
138
139
140
141
142
143 void GenObjCClass(StringRef cls, StringRef ExtSymDefinedIn,
144 StringRef CategoryContextExtSymbolDefinedIn) {
146 CategoryContextExtSymbolDefinedIn);
147 }
148
149
150 void GenObjCCategory(StringRef cls, StringRef cat,
151 StringRef clsExt, StringRef catExt) {
153 }
154
155
156 void GenObjCProperty(StringRef prop, bool isClassProp) {
158 }
159
160
161 void GenObjCProtocol(StringRef prot, StringRef ext) {
163 }
164
169
170 void VisitMSGuidDecl(const MSGuidDecl *D);
171
172
173
174 bool EmitDeclName(const NamedDecl *D);
175};
176}
177
178
179
180
181
182bool USRGenerator::EmitDeclName(const NamedDecl *D) {
185 return true;
186 Out << N;
187 return false;
188}
189
190bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) {
191 if (D->isExternallyVisible())
192 return false;
194 return true;
197 return false;
199 return .isInSystemHeader(Loc);
200}
201
202void USRGenerator::VisitDeclContext(const DeclContext *DC) {
203 if (const NamedDecl *D = dyn_cast(DC))
204 Visit(D);
205 else if (isa(DC))
206 VisitDeclContext(DC->getParent());
207}
208
209void USRGenerator::VisitFieldDecl(const FieldDecl *D) {
210
211
213 Visit(ID);
214 else
216 Out << (isa(D) ? "@" : "@FI@");
217 if (EmitDeclName(D)) {
218
219 IgnoreResults = true;
220 return;
221 }
222}
223
224void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) {
225 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
226 return;
227
228 if (D->getType().isNull()) {
229 IgnoreResults = true;
230 return;
231 }
232
233 const unsigned StartSize = Buf.size();
235 if (Buf.size() == StartSize)
236 GenExtSymbolContainer(D);
237
238 bool IsTemplate = false;
240 IsTemplate = true;
241 Out << "@FT@";
242 VisitTemplateParameterList(FunTmpl->getTemplateParameters());
243 } else
244 Out << "@F@";
245
247
248
249 Policy.SuppressTemplateArgsInCXXConstructors = true;
250 D->getDeclName().print(Out, Policy);
251
252 if ((!LangOpts.CPlusPlus || D->isExternC()) &&
253 ->hasAttr())
254 return;
255
256 if (D->isFunctionTemplateSpecialization()) {
257 Out << '<';
259 D->getTemplateSpecializationArgs()) {
260 for (const auto &Arg : SpecArgs->asArray()) {
261 Out << '#';
262 VisitTemplateArgument(Arg);
263 }
265 D->getTemplateSpecializationArgsAsWritten()) {
266 for (const auto &ArgLoc : SpecArgsWritten->arguments()) {
267 Out << '#';
268 VisitTemplateArgument(ArgLoc.getArgument());
269 }
270 }
271 Out << '>';
272 }
273
274 QualType CanonicalType = D->getType().getCanonicalType();
275
277 for (QualType PT : FPT->param_types()) {
278 Out << '#';
279 VisitType(PT);
280 }
281 }
282 if (D->isVariadic())
283 Out << '.';
284 if (IsTemplate) {
285
286
287
288
289
290 Out << '#';
291 VisitType(D->getReturnType());
292 }
293 Out << '#';
294 if (const CXXMethodDecl *MD = dyn_cast(D)) {
295 if (MD->isStatic())
296 Out << 'S';
297
298 if (unsigned quals = MD->getMethodQualifiers().getCVRUQualifiers())
299 Out << (char)('0' + quals);
300 switch (MD->getRefQualifier()) {
302 case RQ_LValue: Out << '&'; break;
303 case RQ_RValue: Out << "&&"; break;
304 }
305 }
306}
307
308void USRGenerator::VisitNamedDecl(const NamedDecl *D) {
310 Out << "@";
311
312 if (EmitDeclName(D)) {
313
314
315
316
317 IgnoreResults = true;
318 }
319}
320
321void USRGenerator::VisitVarDecl(const VarDecl *D) {
322
323
324
325 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
326 return;
327
329
330 if (VarTemplateDecl *VarTmpl = D->getDescribedVarTemplate()) {
331 Out << "@VT";
332 VisitTemplateParameterList(VarTmpl->getTemplateParameters());
334 = dyn_cast(D)) {
335 Out << "@VP";
336 VisitTemplateParameterList(PartialSpec->getTemplateParameters());
337 }
338
339
340 StringRef s = D->getName();
341
342
343
344
345
346 if (s.empty())
347 IgnoreResults = true;
348 else
349 Out << '@' << s;
350
351
353 = dyn_cast(D)) {
355 Out << '>';
356 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
357 Out << '#';
358 VisitTemplateArgument(Args.get(I));
359 }
360 }
361}
362
363void USRGenerator::VisitBindingDecl(const BindingDecl *D) {
364 if (isLocal(D) && GenLoc(D, true))
365 return;
366 VisitNamedDecl(D);
367}
368
369void USRGenerator::VisitNonTypeTemplateParmDecl(
371 GenLoc(D, true);
372}
373
374void USRGenerator::VisitTemplateTemplateParmDecl(
376 GenLoc(D, true);
377}
378
379void USRGenerator::VisitNamespaceDecl(const NamespaceDecl *D) {
380 if (IgnoreResults)
381 return;
383 if (D->isAnonymousNamespace()) {
384 Out << "@aN";
385 return;
386 }
387 Out << "@N@" << D->getName();
388}
389
391 VisitFunctionDecl(D->getTemplatedDecl());
392}
393
394void USRGenerator::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
395 VisitTagDecl(D->getTemplatedDecl());
396}
397
400 if (!IgnoreResults)
401 Out << "@NA@" << D->getName();
402}
403
405 if (auto *CD = dyn_cast(D->getDeclContext()))
406 return CD;
407 if (auto *ICD = dyn_cast(D->getDeclContext()))
408 return ICD->getCategoryDecl();
409 return nullptr;
410}
411
412void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
414 if (const ObjCProtocolDecl *pd = dyn_cast(container)) {
415 Visit(pd);
416 }
417 else {
418
419
421 if (!ID) {
422 IgnoreResults = true;
423 return;
424 }
426 VisitObjCContainerDecl(ID, CD);
427 }
428
429
430
431 Out << (D->isInstanceMethod() ? "(im)" : "(cm)")
433}
434
438 default:
439 llvm_unreachable("Invalid ObjC container.");
440 case Decl::ObjCInterface:
441 case Decl::ObjCImplementation:
444 break;
445 case Decl::ObjCCategory: {
448 if (!ID) {
449
450
451
452
453 IgnoreResults = true;
454 return;
455 }
456
457
459 Out << "objc(ext)" << ID->getName() << '@';
460 GenLoc(CD, true);
461 }
462 else
463 GenObjCCategory(ID->getName(), CD->getName(),
466
467 break;
468 }
469 case Decl::ObjCCategoryImpl: {
472 if (!ID) {
473
474
475
476
477 IgnoreResults = true;
478 return;
479 }
480 GenObjCCategory(ID->getName(), CD->getName(),
483 break;
484 }
485 case Decl::ObjCProtocol: {
488 break;
489 }
490 }
491}
492
493void USRGenerator::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
494
495
498 else
500 GenObjCProperty(D->getName(), D->isClassProperty());
501}
502
505 VisitObjCPropertyDecl(PD);
506 return;
507 }
508
509 IgnoreResults = true;
510}
511
512void USRGenerator::VisitTagDecl(const TagDecl *D) {
513
514
515 if (!isa(D) &&
516 ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
517 return;
518
519 GenExtSymbolContainer(D);
520
523
524 bool AlreadyStarted = false;
525 if (const CXXRecordDecl *CXXRecord = dyn_cast(D)) {
527 AlreadyStarted = true;
528
529 switch (D->getTagKind()) {
530 case TagTypeKind::Interface:
531 case TagTypeKind::Class:
532 case TagTypeKind::Struct:
533 Out << "@ST";
534 break;
535 case TagTypeKind::Union:
536 Out << "@UT";
537 break;
538 case TagTypeKind::Enum:
539 llvm_unreachable("enum template");
540 }
541 VisitTemplateParameterList(ClassTmpl->getTemplateParameters());
543 = dyn_cast(CXXRecord)) {
544 AlreadyStarted = true;
545
546 switch (D->getTagKind()) {
547 case TagTypeKind::Interface:
548 case TagTypeKind::Class:
549 case TagTypeKind::Struct:
550 Out << "@SP";
551 break;
552 case TagTypeKind::Union:
553 Out << "@UP";
554 break;
555 case TagTypeKind::Enum:
556 llvm_unreachable("enum partial specialization");
557 }
558 VisitTemplateParameterList(PartialSpec->getTemplateParameters());
559 }
560 }
561
562 if (!AlreadyStarted) {
563 switch (D->getTagKind()) {
564 case TagTypeKind::Interface:
565 case TagTypeKind::Class:
566 case TagTypeKind::Struct:
567 Out << "@S";
568 break;
569 case TagTypeKind::Union:
570 Out << "@U";
571 break;
572 case TagTypeKind::Enum:
573 Out << "@E";
574 break;
575 }
576 }
577
578 Out << '@';
579 assert(Buf.size() > 0);
580 const unsigned off = Buf.size() - 1;
581
582 if (EmitDeclName(D)) {
583 if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) {
584 Buf[off] = 'A';
585 Out << '@' << *TD;
586 } else {
587 if (D->isEmbeddedInDeclarator() && ->isFreeStanding()) {
589 } else {
590 Buf[off] = 'a';
591 if (auto *ED = dyn_cast(D)) {
592
593
594 auto enum_range = ED->enumerators();
595 if (enum_range.begin() != enum_range.end()) {
596 Out << '@' << **enum_range.begin();
597 }
598 }
599 }
600 }
601 }
602
603
605 = dyn_cast(D)) {
607 Out << '>';
608 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
609 Out << '#';
610 VisitTemplateArgument(Args.get(I));
611 }
612 }
613}
614
615void USRGenerator::VisitTypedefDecl(const TypedefDecl *D) {
616 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
617 return;
619 if (const NamedDecl *DCN = dyn_cast(DC))
620 Visit(DCN);
621 Out << "@T@";
622 Out << D->getName();
623}
624
626 GenLoc(D, true);
627}
628
629void USRGenerator::GenExtSymbolContainer(const NamedDecl *D) {
631 if (!Container.empty())
632 Out << "@M@" << Container;
633}
634
635bool USRGenerator::GenLoc(const Decl *D, bool IncludeOffset) {
636 if (generatedLoc)
637 return IgnoreResults;
638 generatedLoc = true;
639
640
641 if () {
642 IgnoreResults = true;
643 return true;
644 }
645
646
648
649 IgnoreResults =
652
653 return IgnoreResults;
654}
655
658
664 NNS->print(Out, PO);
665}
666
667void USRGenerator::VisitType(QualType T) {
668
669
670
672
673 do {
676 unsigned qVal = 0;
678 qVal |= 0x1;
680 qVal |= 0x2;
682 qVal |= 0x4;
683 if(qVal)
684 Out << ((char) ('0' + qVal));
685
686
687
689 Out << 'P';
690 T = Expansion->getPattern();
691 }
692
694 switch (BT->getKind()) {
695 case BuiltinType::Void:
696 Out << 'v'; break;
697 case BuiltinType::Bool:
698 Out << 'b'; break;
699 case BuiltinType::UChar:
700 Out << 'c'; break;
701 case BuiltinType::Char8:
702 Out << 'u'; break;
703 case BuiltinType::Char16:
704 Out << 'q'; break;
705 case BuiltinType::Char32:
706 Out << 'w'; break;
707 case BuiltinType::UShort:
708 Out << 's'; break;
709 case BuiltinType::UInt:
710 Out << 'i'; break;
711 case BuiltinType::ULong:
712 Out << 'l'; break;
713 case BuiltinType::ULongLong:
714 Out << 'k'; break;
715 case BuiltinType::UInt128:
716 Out << 'j'; break;
717 case BuiltinType::Char_U:
718 case BuiltinType::Char_S:
719 Out << 'C'; break;
720 case BuiltinType::SChar:
721 Out << 'r'; break;
722 case BuiltinType::WChar_S:
723 case BuiltinType::WChar_U:
724 Out << 'W'; break;
725 case BuiltinType::Short:
726 Out << 'S'; break;
727 case BuiltinType::Int:
728 Out << 'I'; break;
729 case BuiltinType::Long:
730 Out << 'L'; break;
731 case BuiltinType::LongLong:
732 Out << 'K'; break;
733 case BuiltinType::Int128:
734 Out << 'J'; break;
735 case BuiltinType::Float16:
736 case BuiltinType::Half:
737 Out << 'h'; break;
738 case BuiltinType::Float:
739 Out << 'f'; break;
740 case BuiltinType::Double:
741 Out << 'd'; break;
742 case BuiltinType::LongDouble:
743 Out << 'D'; break;
744 case BuiltinType::Float128:
745 Out << 'Q'; break;
746 case BuiltinType::NullPtr:
747 Out << 'n'; break;
748#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
749 case BuiltinType::Id: \
750 Out << "@BT@" << #Suffix << "_" << #ImgType; break;
751#include "clang/Basic/OpenCLImageTypes.def"
752#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
753 case BuiltinType::Id: \
754 Out << "@BT@" << #ExtType; break;
755#include "clang/Basic/OpenCLExtensionTypes.def"
756 case BuiltinType::OCLEvent:
757 Out << "@BT@OCLEvent"; break;
758 case BuiltinType::OCLClkEvent:
759 Out << "@BT@OCLClkEvent"; break;
760 case BuiltinType::OCLQueue:
761 Out << "@BT@OCLQueue"; break;
762 case BuiltinType::OCLReserveID:
763 Out << "@BT@OCLReserveID"; break;
764 case BuiltinType::OCLSampler:
765 Out << "@BT@OCLSampler"; break;
766#define SVE_TYPE(Name, Id, SingletonId) \
767 case BuiltinType::Id: \
768 Out << "@BT@" << Name; break;
769#include "clang/Basic/AArch64SVEACLETypes.def"
770#define PPC_VECTOR_TYPE(Name, Id, Size) \
771 case BuiltinType::Id: \
772 Out << "@BT@" << #Name; break;
773#include "clang/Basic/PPCTypes.def"
774#define RVV_TYPE(Name, Id, SingletonId) \
775 case BuiltinType::Id: \
776 Out << "@BT@" << Name; break;
777#include "clang/Basic/RISCVVTypes.def"
778#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
779#include "clang/Basic/WebAssemblyReferenceTypes.def"
780#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
781 case BuiltinType::Id: \
782 Out << "@BT@" << #Name; \
783 break;
784#include "clang/Basic/AMDGPUTypes.def"
785#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
786 case BuiltinType::Id: \
787 Out << "@BT@" << #Name; \
788 break;
789#include "clang/Basic/HLSLIntangibleTypes.def"
790 case BuiltinType::ShortAccum:
791 Out << "@BT@ShortAccum"; break;
792 case BuiltinType::Accum:
793 Out << "@BT@Accum"; break;
794 case BuiltinType::LongAccum:
795 Out << "@BT@LongAccum"; break;
796 case BuiltinType::UShortAccum:
797 Out << "@BT@UShortAccum"; break;
798 case BuiltinType::UAccum:
799 Out << "@BT@UAccum"; break;
800 case BuiltinType::ULongAccum:
801 Out << "@BT@ULongAccum"; break;
802 case BuiltinType::ShortFract:
803 Out << "@BT@ShortFract"; break;
804 case BuiltinType::Fract:
805 Out << "@BT@Fract"; break;
806 case BuiltinType::LongFract:
807 Out << "@BT@LongFract"; break;
808 case BuiltinType::UShortFract:
809 Out << "@BT@UShortFract"; break;
810 case BuiltinType::UFract:
811 Out << "@BT@UFract"; break;
812 case BuiltinType::ULongFract:
813 Out << "@BT@ULongFract"; break;
814 case BuiltinType::SatShortAccum:
815 Out << "@BT@SatShortAccum"; break;
816 case BuiltinType::SatAccum:
817 Out << "@BT@SatAccum"; break;
818 case BuiltinType::SatLongAccum:
819 Out << "@BT@SatLongAccum"; break;
820 case BuiltinType::SatUShortAccum:
821 Out << "@BT@SatUShortAccum"; break;
822 case BuiltinType::SatUAccum:
823 Out << "@BT@SatUAccum"; break;
824 case BuiltinType::SatULongAccum:
825 Out << "@BT@SatULongAccum"; break;
826 case BuiltinType::SatShortFract:
827 Out << "@BT@SatShortFract"; break;
828 case BuiltinType::SatFract:
829 Out << "@BT@SatFract"; break;
830 case BuiltinType::SatLongFract:
831 Out << "@BT@SatLongFract"; break;
832 case BuiltinType::SatUShortFract:
833 Out << "@BT@SatUShortFract"; break;
834 case BuiltinType::SatUFract:
835 Out << "@BT@SatUFract"; break;
836 case BuiltinType::SatULongFract:
837 Out << "@BT@SatULongFract"; break;
838 case BuiltinType::BFloat16:
839 Out << "@BT@__bf16"; break;
840 case BuiltinType::Ibm128:
841 Out << "@BT@__ibm128"; break;
842 case BuiltinType::ObjCId:
843 Out << 'o'; break;
844 case BuiltinType::ObjCClass:
845 Out << 'O'; break;
846 case BuiltinType::ObjCSel:
847 Out << 'e'; break;
848#define BUILTIN_TYPE(Id, SingletonId)
849#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
850#include "clang/AST/BuiltinTypes.def"
851 case BuiltinType::Dependent:
852
853
854 IgnoreResults = true;
855 break;
856 }
857 return;
858 }
859
860
861
862 llvm::DenseMap<const Type *, unsigned>::iterator Substitution
863 = TypeSubstitutions.find(T.getTypePtr());
864 if (Substitution != TypeSubstitutions.end()) {
865 Out << 'S' << Substitution->second << '_';
866 return;
867 } else {
868
869 unsigned Number = TypeSubstitutions.size();
870 TypeSubstitutions[T.getTypePtr()] = Number;
871 }
872
874 Out << '*';
876 continue;
877 }
879 Out << '*';
881 continue;
882 }
884 Out << "&&";
886 continue;
887 }
889 Out << '&';
891 continue;
892 }
894 Out << 'F';
895 VisitType(FT->getReturnType());
896 Out << '(';
897 for (const auto &I : FT->param_types()) {
898 Out << '#';
899 VisitType(I);
900 }
901 Out << ')';
902 if (FT->isVariadic())
903 Out << '.';
904 return;
905 }
907 Out << 'B';
909 continue;
910 }
912 Out << '<';
913 T = CT->getElementType();
914 continue;
915 }
917 Out << '$';
918 VisitTagDecl(TT->getDecl());
919 return;
920 }
922 Out << '$';
923 VisitObjCInterfaceDecl(OIT->getDecl());
924 return;
925 }
927 Out << 'Q';
928 VisitType(OIT->getBaseType());
929 for (auto *Prot : OIT->getProtocols())
930 VisitObjCProtocolDecl(Prot);
931 return;
932 }
934 Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
935 return;
936 }
939 Out << '>';
940 VisitTemplateName(Spec->getTemplateName());
941 Out << Spec->template_arguments().size();
942 for (const auto &Arg : Spec->template_arguments())
943 VisitTemplateArgument(Arg);
944 return;
945 }
947 Out << '^';
949 Out << ':' << DNT->getIdentifier()->getName();
950 return;
951 }
953 T = InjT->getInjectedSpecializationType();
954 continue;
955 }
958 Out << VT->getNumElements();
959 T = VT->getElementType();
960 continue;
961 }
962 if (const auto *const AT = dyn_cast(T)) {
963 Out << '{';
964 switch (AT->getSizeModifier()) {
965 case ArraySizeModifier::Static:
966 Out << 's';
967 break;
968 case ArraySizeModifier::Star:
969 Out << '*';
970 break;
971 case ArraySizeModifier::Normal:
972 Out << 'n';
973 break;
974 }
975 if (const auto *const CAT = dyn_cast(T))
976 Out << CAT->getSize();
977
978 T = AT->getElementType();
979 continue;
980 }
981
982
983 Out << ' ';
984 break;
985 } while (true);
986}
987
988void USRGenerator::VisitTemplateParameterList(
990 if (!Params)
991 return;
992 Out << '>' << Params->size();
994 PEnd = Params->end();
996 Out << '#';
997 if (isa(*P)) {
998 if (cast(*P)->isParameterPack())
999 Out<< 'p';
1000 Out << 'T';
1001 continue;
1002 }
1003
1005 if (NTTP->isParameterPack())
1006 Out << 'p';
1007 Out << 'N';
1008 VisitType(NTTP->getType());
1009 continue;
1010 }
1011
1014 Out << 'p';
1015 Out << 't';
1017 }
1018}
1019
1020void USRGenerator::VisitTemplateName(TemplateName Name) {
1021 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
1023 = dyn_cast(Template)) {
1024 Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
1025 return;
1026 }
1027
1028 Visit(Template);
1029 return;
1030 }
1031
1032
1033}
1034
1035void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) {
1036 switch (Arg.getKind()) {
1038 break;
1039
1042 break;
1043
1045 break;
1046
1048 Out << 'P';
1049 [[fallthrough]];
1052 break;
1053
1055
1056 break;
1057
1061 VisitTemplateArgument(P);
1062 break;
1063
1066 break;
1067
1069 Out << 'V';
1072 break;
1073
1075 Out << 'S';
1079 Out << Hash.CalculateHash();
1080 break;
1081 }
1082 }
1083}
1084
1086 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1087 return;
1089 Out << "@UUV@";
1091 EmitDeclName(D);
1092}
1093
1095 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1096 return;
1098 Out << "@UUT@";
1100 Out << D->getName();
1101}
1102
1103void USRGenerator::VisitConceptDecl(const ConceptDecl *D) {
1104 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1105 return;
1107 Out << "@CT@";
1108 EmitDeclName(D);
1109}
1110
1111void USRGenerator::VisitMSGuidDecl(const MSGuidDecl *D) {
1113 Out << "@MG@";
1114 D->NamedDecl::printName(Out);
1115}
1116
1117
1118
1119
1120
1122 StringRef CatSymDefinedIn,
1123 raw_ostream &OS) {
1124 if (ClsSymDefinedIn.empty() && CatSymDefinedIn.empty())
1125 return;
1126 if (CatSymDefinedIn.empty()) {
1127 OS << "@M@" << ClsSymDefinedIn << '@';
1128 return;
1129 }
1130 OS << "@CM@" << CatSymDefinedIn << '@';
1131 if (ClsSymDefinedIn != CatSymDefinedIn) {
1132 OS << ClsSymDefinedIn << '@';
1133 }
1134}
1135
1137 StringRef ExtSymDefinedIn,
1138 StringRef CategoryContextExtSymbolDefinedIn) {
1140 CategoryContextExtSymbolDefinedIn, OS);
1141 OS << "objc(cs)" << Cls;
1142}
1143
1145 raw_ostream &OS,
1146 StringRef ClsSymDefinedIn,
1147 StringRef CatSymDefinedIn) {
1149 OS << "objc(cy)" << Cls << '@' << Cat;
1150}
1151
1153 OS << '@' << Ivar;
1154}
1155
1157 bool IsInstanceMethod,
1158 raw_ostream &OS) {
1159 OS << (IsInstanceMethod ? "(im)" : "(cm)") << Sel;
1160}
1161
1163 raw_ostream &OS) {
1164 OS << (isClassProp ? "(cpy)" : "(py)") << Prop;
1165}
1166
1168 StringRef ExtSymDefinedIn) {
1169 if (!ExtSymDefinedIn.empty())
1170 OS << "@M@" << ExtSymDefinedIn << '@';
1171 OS << "objc(pl)" << Prot;
1172}
1173
1175 StringRef ExtSymDefinedIn) {
1176 if (!ExtSymDefinedIn.empty())
1177 OS << "@M@" << ExtSymDefinedIn;
1178 OS << "@E@" << EnumName;
1179}
1180
1182 raw_ostream &OS) {
1183 OS << '@' << EnumConstantName;
1184}
1185
1188 if ()
1189 return true;
1191}
1192
1195 if ()
1196 return true;
1197
1198
1199
1200
1201
1203 if (auto *ExternalSymAttr = CD->getAttr()) {
1204 if (!ExternalSymAttr->getUSR().empty()) {
1205 llvm::raw_svector_ostream Out(Buf);
1206 Out << ExternalSymAttr->getUSR();
1207 return false;
1208 }
1209 }
1210 USRGenerator UG(&D->getASTContext(), Buf, LangOpts);
1211 UG.Visit(D);
1212 return UG.ignoreResults();
1213}
1214
1218 if (!MD)
1219 return true;
1221 SM, Buf);
1222
1223}
1224
1228 if (MacroName.empty())
1229 return true;
1230
1231 llvm::raw_svector_ostream Out(Buf);
1232
1233
1234
1235 bool ShouldGenerateLocation = Loc.isValid() && .isInSystemHeader(Loc);
1236
1238 if (ShouldGenerateLocation)
1240 Out << "@macro@";
1241 Out << MacroName;
1242 return false;
1243}
1244
1248}
1249
1253 if (T.isNull())
1254 return true;
1255 T = T.getCanonicalType();
1256
1257 USRGenerator UG(&Ctx, Buf, LangOpts);
1258 UG.VisitType(T);
1259 return UG.ignoreResults();
1260}
1261
1263 raw_ostream &OS) {
1267 return true;
1269}
1270
1272 raw_ostream &OS) {
1275}
1276
1278 raw_ostream &OS) {
1280}
1281
1283 raw_ostream &OS) {
1284 OS << "@M@" << ModName;
1285 return false;
1286}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::FileManager interface and associated types.
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes,...
static void combineClassAndCategoryExtContainers(StringRef ClsSymDefinedIn, StringRef CatSymDefinedIn, raw_ostream &OS)
static bool printLoc(llvm::raw_ostream &OS, SourceLocation Loc, const SourceManager &SM, bool IncludeOffset)
static const ObjCCategoryDecl * getCategoryContext(const NamedDecl *D)
static void printQualifier(llvm::raw_ostream &Out, const LangOptions &LangOpts, NestedNameSpecifier *NNS)
static StringRef GetExternalSourceContainer(const NamedDecl *D)
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
const LangOptions & getLangOpts() const
const ObjCInterfaceDecl * getObjContainingInterface(const NamedDecl *ND) const
Returns the Objective-C interface that ND belongs to if it is an Objective-C method/property/ivar etc...
A binding in a decomposition declaration.
This class is used for builtin types like 'int'.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
Declaration of a class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
Complex values, per C99 6.2.5p11.
Declaration of a C++20 concept.
A simple visitor class that helps create declaration visitors.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Decl - This represents one declaration (or definition), e.g.
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
ASTContext & getASTContext() const LLVM_READONLY
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
SourceLocation getLocation() const
DeclContext * getDeclContext()
SourceLocation getBeginLoc() const LLVM_READONLY
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
bool isEmpty() const
Evaluates true when this declaration name is empty.
Represents a qualified type name for which the type name is dependent.
Represents a member of a struct/union/class.
StringRef getName() const
The name of this FileEntry.
Represents a function declaration or definition.
Represents a prototype with parameter type info, e.g.
Declaration of a template function.
StringRef getName() const
Return the actual identifier string.
The injected class name of a C++ class template or class template partial specialization.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a linkage specification.
Record the location of a macro definition.
SourceLocation getLocation() const
Retrieve the location of the macro name in the definition.
const IdentifierInfo * getName() const
Retrieve the name of the macro being defined.
Describes a module or submodule.
Module * Parent
The parent of this module.
std::string Name
The name of this module.
This represents a decl that may have a name.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Represents a C++ namespace alias.
Represent a C++ namespace.
Represents a C++ nested name specifier, such as "\::std::vector::".
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
void AddStructuralValue(const APValue &)
ObjCCategoryDecl - Represents a category declaration.
ObjCInterfaceDecl * getClassInterface()
bool IsClassExtension() const
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
ObjCContainerDecl - Represents a container for method declarations.
const ObjCInterfaceDecl * getClassInterface() const
Represents an ObjC class declaration.
Interfaces are the core concept in Objective-C for object oriented design.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents a pointer to an Objective C object.
Represents a class type in Objective C.
Represents one property declaration in an Objective-C interface.
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Represents an Objective-C protocol declaration.
Represents a pack expansion of types.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
The collection of all-type qualifiers we support.
An rvalue reference type, per C++11 [dcl.ref].
Base for LValueReferenceType and RValueReferenceType.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
Represents the declaration of a struct/union/class/enum.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl *const * const_iterator
Iterates through the template parameters in this list.
Represents a type template specialization; the template must be a class template, a type alias templa...
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
Declaration of a template type parameter.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isExtVectorType() const
const T * getAs() const
Member-template getAs'.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Base class for declarations which introduce a typedef-name.
Represents a dependent using declaration which was marked with typename.
Represents a dependent using declaration which was not marked with typename.
Represents a C++ using-declaration.
Represents C++ using-directive.
Represents a variable declaration or definition.
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
Represents a GCC generic vector type.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS)
Generate a USR for a top-level module name, including the USR prefix.
static StringRef getUSRSpacePrefix()
void generateUSRForObjCCategory(StringRef Cls, StringRef Cat, raw_ostream &OS, StringRef ClsExtSymbolDefinedIn="", StringRef CatExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C class category.
bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS)
Generate a USR for a module, including the USR prefix.
bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS)
Generate a USR fragment for a module name.
bool generateUSRForMacro(const MacroDefinitionRecord *MD, const SourceManager &SM, SmallVectorImpl< char > &Buf)
Generate a USR for a macro, including the USR prefix.
void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS)
Generate a USR fragment for an Objective-C property.
void generateUSRForEnumConstant(StringRef EnumConstantName, raw_ostream &OS)
Generate a USR fragment for an enum constant.
void generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS)
Generate a USR fragment for an Objective-C instance variable.
void generateUSRForObjCMethod(StringRef Sel, bool IsInstanceMethod, raw_ostream &OS)
Generate a USR fragment for an Objective-C method.
bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl< char > &Buf)
Generates a USR for a type.
void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS, StringRef ExtSymbolDefinedIn="", StringRef CategoryContextExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C class.
void generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS, StringRef ExtSymbolDefinedIn="")
Generate USR fragment for a global (non-nested) enum.
void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS, StringRef ExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C protocol.
bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS)
Generate a USR fragment for a module.
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
The JSON file list parser is used to communicate input to InstallAPI.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
const FunctionProtoType * T
Represents an explicit template argument list in C++, e.g., the "" in "sort".
Describes how types, statements, expressions, and declarations should be printed.
unsigned SuppressUnwrittenScope
Suppress printing parts of scope specifiers that are never written, e.g., for anonymous namespaces.
unsigned AnonymousTagLocations
When printing an anonymous tag name, also print the location of that entity (e.g.,...
unsigned ConstantArraySizeAsWritten
Whether we should print the sizes of constant array expressions as written in the sources.
unsigned SuppressTagKeyword
Whether type printing should skip printing the tag keyword.