17#include "llvm/Support/Path.h"
18#include "llvm/Support/raw_ostream.h"
59 OS << llvm::sys::path::filename(FE->
getName());
77 return attr->getDefinedIn();
84 SmallVectorImpl<char> &Buf;
85 llvm::raw_svector_ostream Out;
87 const LangOptions &LangOpts;
88 bool IgnoreResults =
false;
93 bool GeneratedFilename =
false;
95 llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
98 USRGenerator(ASTContext *Ctx, SmallVectorImpl<char> &Buf,
99 const LangOptions &LangOpts)
100 : Buf(Buf), Out(Buf), Context(Ctx), LangOpts(LangOpts) {
105 bool ignoreResults()
const {
return IgnoreResults; }
108 void VisitDeclContext(
const DeclContext *D);
109 void VisitFieldDecl(
const FieldDecl *D);
110 void VisitFunctionDecl(
const FunctionDecl *D);
111 void VisitNamedDecl(
const NamedDecl *D);
112 void VisitNamespaceDecl(
const NamespaceDecl *D);
113 void VisitNamespaceAliasDecl(
const NamespaceAliasDecl *D);
114 void VisitFunctionTemplateDecl(
const FunctionTemplateDecl *D);
115 void VisitClassTemplateDecl(
const ClassTemplateDecl *D);
116 void VisitObjCContainerDecl(
const ObjCContainerDecl *CD,
117 const ObjCCategoryDecl *CatD =
nullptr);
118 void VisitObjCMethodDecl(
const ObjCMethodDecl *MD);
119 void VisitObjCPropertyDecl(
const ObjCPropertyDecl *D);
120 void VisitObjCPropertyImplDecl(
const ObjCPropertyImplDecl *D);
121 void VisitTagDecl(
const TagDecl *D);
122 void VisitTypedefDecl(
const TypedefDecl *D);
123 void VisitTemplateTypeParmDecl(
const TemplateTypeParmDecl *D);
124 void VisitVarDecl(
const VarDecl *D);
125 void VisitBindingDecl(
const BindingDecl *D);
126 void VisitNonTypeTemplateParmDecl(
const NonTypeTemplateParmDecl *D);
127 void VisitTemplateTemplateParmDecl(
const TemplateTemplateParmDecl *D);
128 void VisitUnresolvedUsingValueDecl(
const UnresolvedUsingValueDecl *D);
129 void VisitUnresolvedUsingTypenameDecl(
const UnresolvedUsingTypenameDecl *D);
130 void VisitConceptDecl(
const ConceptDecl *D);
132 void VisitLinkageSpecDecl(
const LinkageSpecDecl *D) {
133 IgnoreResults =
true;
136 void VisitUsingDirectiveDecl(
const UsingDirectiveDecl *D) {
137 IgnoreResults =
true;
140 void VisitUsingDecl(
const UsingDecl *D) {
144 bool EmittedDeclName = !EmitDeclName(D);
145 assert(EmittedDeclName &&
"EmitDeclName can not fail for UsingDecls");
146 (void)EmittedDeclName;
149 bool ShouldGenerateLocation(
const NamedDecl *D);
151 bool isLocal(
const NamedDecl *D) {
155 void GenExtSymbolContainer(
const NamedDecl *D);
159 bool GenLoc(
const Decl *D,
bool IncludeOffset);
168 void GenObjCClass(StringRef cls, StringRef ExtSymDefinedIn,
169 StringRef CategoryContextExtSymbolDefinedIn) {
171 CategoryContextExtSymbolDefinedIn);
175 void GenObjCCategory(StringRef cls, StringRef cat, StringRef clsExt,
181 void GenObjCProperty(StringRef prop,
bool isClassProp) {
186 void GenObjCProtocol(StringRef prot, StringRef ext) {
190 void VisitType(QualType
T);
191 void VisitTemplateParameterList(
const TemplateParameterList *Params);
193 void VisitTemplateArgument(
const TemplateArgument &Arg);
195 void VisitMSGuidDecl(
const MSGuidDecl *D);
196 void VisitTemplateParamObjectDecl(
const TemplateParamObjectDecl *D);
200 bool EmitDeclName(
const NamedDecl *D);
208bool USRGenerator::EmitDeclName(
const NamedDecl *D) {
216bool USRGenerator::ShouldGenerateLocation(
const NamedDecl *D) {
228void USRGenerator::VisitDeclContext(
const DeclContext *DC) {
229 if (
const NamedDecl *D = dyn_cast<NamedDecl>(DC))
235void USRGenerator::VisitFieldDecl(
const FieldDecl *D) {
242 Out << (isa<ObjCIvarDecl>(D) ?
"@" :
"@FI@");
243 if (EmitDeclName(D)) {
245 IgnoreResults =
true;
250void USRGenerator::VisitFunctionDecl(
const FunctionDecl *D) {
251 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
255 IgnoreResults =
true;
259 const unsigned StartSize = Buf.size();
261 if (Buf.size() == StartSize)
262 GenExtSymbolContainer(D);
264 bool IsTemplate =
false;
268 VisitTemplateParameterList(FunTmpl->getTemplateParameters());
272 PrintingPolicy Policy(LangOpts);
275 Policy.SuppressTemplateArgsInCXXConstructors =
true;
278 if ((!LangOpts.CPlusPlus || D->
isExternC()) &&
279 !D->
hasAttr<OverloadableAttr>())
284 if (
const TemplateArgumentList *SpecArgs =
286 for (
const auto &Arg : SpecArgs->asArray()) {
288 VisitTemplateArgument(Arg);
290 }
else if (
const ASTTemplateArgumentListInfo *SpecArgsWritten =
292 for (
const auto &ArgLoc : SpecArgsWritten->arguments()) {
294 VisitTemplateArgument(ArgLoc.getArgument());
302 if (
const auto *FPT = CanonicalType->
getAs<FunctionProtoType>()) {
303 for (QualType PT : FPT->param_types()) {
320 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
324 if (
unsigned quals = MD->getMethodQualifiers().getCVRUQualifiers())
325 Out << (char)(
'0' + quals);
326 switch (MD->getRefQualifier()) {
339void USRGenerator::VisitNamedDecl(
const NamedDecl *D) {
343 if (EmitDeclName(D)) {
348 IgnoreResults =
true;
352void USRGenerator::VisitVarDecl(
const VarDecl *D) {
356 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
363 VisitTemplateParameterList(VarTmpl->getTemplateParameters());
364 }
else if (
const VarTemplatePartialSpecializationDecl *PartialSpec =
365 dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
367 VisitTemplateParameterList(PartialSpec->getTemplateParameters());
378 IgnoreResults =
true;
383 if (
const VarTemplateSpecializationDecl *Spec =
384 dyn_cast<VarTemplateSpecializationDecl>(D)) {
385 const TemplateArgumentList &Args = Spec->getTemplateArgs();
387 for (
unsigned I = 0, N = Args.
size(); I != N; ++I) {
389 VisitTemplateArgument(Args.
get(I));
394void USRGenerator::VisitBindingDecl(
const BindingDecl *D) {
395 if (isLocal(D) && GenLoc(D,
true))
400void USRGenerator::VisitNonTypeTemplateParmDecl(
401 const NonTypeTemplateParmDecl *D) {
405void USRGenerator::VisitTemplateTemplateParmDecl(
406 const TemplateTemplateParmDecl *D) {
410void USRGenerator::VisitNamespaceDecl(
const NamespaceDecl *D) {
421void USRGenerator::VisitFunctionTemplateDecl(
const FunctionTemplateDecl *D) {
425void USRGenerator::VisitClassTemplateDecl(
const ClassTemplateDecl *D) {
429void USRGenerator::VisitNamespaceAliasDecl(
const NamespaceAliasDecl *D) {
438 if (
auto *ICD = dyn_cast<ObjCCategoryImplDecl>(D->
getDeclContext()))
439 return ICD->getCategoryDecl();
443void USRGenerator::VisitObjCMethodDecl(
const ObjCMethodDecl *D) {
445 if (
const ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
452 IgnoreResults =
true;
456 VisitObjCContainerDecl(ID, CD);
465void USRGenerator::VisitObjCContainerDecl(
const ObjCContainerDecl *D,
466 const ObjCCategoryDecl *CatD) {
469 llvm_unreachable(
"Invalid ObjC container.");
470 case Decl::ObjCInterface:
471 case Decl::ObjCImplementation:
475 case Decl::ObjCCategory: {
483 IgnoreResults =
true;
489 Out <<
"objc(ext)" <<
ID->getName() <<
'@';
492 GenObjCCategory(
ID->getName(), CD->
getName(),
498 case Decl::ObjCCategoryImpl: {
506 IgnoreResults =
true;
509 GenObjCCategory(
ID->getName(), CD->
getName(),
514 case Decl::ObjCProtocol: {
522void USRGenerator::VisitObjCPropertyDecl(
const ObjCPropertyDecl *D) {
532void USRGenerator::VisitObjCPropertyImplDecl(
const ObjCPropertyImplDecl *D) {
534 VisitObjCPropertyDecl(PD);
538 IgnoreResults =
true;
541void USRGenerator::VisitTagDecl(
const TagDecl *D) {
545 GenLoc(D, isLocal(D)))
548 GenExtSymbolContainer(D);
553 bool AlreadyStarted =
false;
554 if (
const CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) {
555 if (ClassTemplateDecl *ClassTmpl =
CXXRecord->getDescribedClassTemplate()) {
556 AlreadyStarted =
true;
559 case TagTypeKind::Interface:
560 case TagTypeKind::Class:
561 case TagTypeKind::Struct:
564 case TagTypeKind::Union:
567 case TagTypeKind::Enum:
568 llvm_unreachable(
"enum template");
570 VisitTemplateParameterList(ClassTmpl->getTemplateParameters());
571 }
else if (
const ClassTemplatePartialSpecializationDecl *PartialSpec =
572 dyn_cast<ClassTemplatePartialSpecializationDecl>(
574 AlreadyStarted =
true;
577 case TagTypeKind::Interface:
578 case TagTypeKind::Class:
579 case TagTypeKind::Struct:
582 case TagTypeKind::Union:
585 case TagTypeKind::Enum:
586 llvm_unreachable(
"enum partial specialization");
588 VisitTemplateParameterList(PartialSpec->getTemplateParameters());
592 if (!AlreadyStarted) {
594 case TagTypeKind::Interface:
595 case TagTypeKind::Class:
596 case TagTypeKind::Struct:
599 case TagTypeKind::Union:
602 case TagTypeKind::Enum:
609 assert(Buf.size() > 0);
610 const unsigned off = Buf.size() - 1;
612 if (EmitDeclName(D)) {
621 if (
auto *ED = dyn_cast<EnumDecl>(D)) {
624 auto enum_range = ED->enumerators();
625 if (enum_range.begin() != enum_range.end()) {
626 Out <<
'@' << **enum_range.begin();
634 if (
const ClassTemplateSpecializationDecl *Spec =
635 dyn_cast<ClassTemplateSpecializationDecl>(D)) {
636 const TemplateArgumentList &Args = Spec->getTemplateArgs();
638 for (
unsigned I = 0, N = Args.
size(); I != N; ++I) {
640 VisitTemplateArgument(Args.
get(I));
645void USRGenerator::VisitTypedefDecl(
const TypedefDecl *D) {
646 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
649 if (
const NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
655void USRGenerator::VisitTemplateTypeParmDecl(
const TemplateTypeParmDecl *D) {
659void USRGenerator::GenExtSymbolContainer(
const NamedDecl *D) {
661 if (!Container.empty())
662 Out <<
"@M@" << Container;
665bool USRGenerator::GenLoc(
const Decl *D,
bool IncludeOffset) {
668 IgnoreResults =
true;
672 if (!IncludeOffset && GeneratedFilename)
673 return IgnoreResults;
675 bool PrintErr =
false;
679 if (!GeneratedFilename) {
680 GeneratedFilename =
true;
687 IgnoreResults = IgnoreResults || PrintErr;
688 return IgnoreResults;
703void USRGenerator::VisitType(QualType
T) {
707 ASTContext &Ctx = *Context;
711 Qualifiers Q =
T.getQualifiers();
720 Out << ((char)(
'0' + qVal));
724 if (
const PackExpansionType *Expansion =
T->
getAs<PackExpansionType>()) {
726 T = Expansion->getPattern();
729 if (
const BuiltinType *BT =
T->
getAs<BuiltinType>()) {
730 switch (BT->getKind()) {
731 case BuiltinType::Void:
734 case BuiltinType::Bool:
737 case BuiltinType::UChar:
740 case BuiltinType::Char8:
743 case BuiltinType::Char16:
746 case BuiltinType::Char32:
749 case BuiltinType::UShort:
752 case BuiltinType::UInt:
755 case BuiltinType::ULong:
758 case BuiltinType::ULongLong:
761 case BuiltinType::UInt128:
764 case BuiltinType::Char_U:
765 case BuiltinType::Char_S:
768 case BuiltinType::SChar:
771 case BuiltinType::WChar_S:
772 case BuiltinType::WChar_U:
775 case BuiltinType::Short:
778 case BuiltinType::Int:
781 case BuiltinType::Long:
784 case BuiltinType::LongLong:
787 case BuiltinType::Int128:
790 case BuiltinType::Float16:
791 case BuiltinType::Half:
794 case BuiltinType::Float:
797 case BuiltinType::Double:
800 case BuiltinType::LongDouble:
803 case BuiltinType::Float128:
806 case BuiltinType::NullPtr:
809 case BuiltinType::MetaInfo:
810 Out <<
"@BT@MetaInfo";
812#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
813 case BuiltinType::Id: \
814 Out << "@BT@" << #Suffix << "_" << #ImgType; \
816#include "clang/Basic/OpenCLImageTypes.def"
817#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
818 case BuiltinType::Id: \
819 Out << "@BT@" << #ExtType; \
821#include "clang/Basic/OpenCLExtensionTypes.def"
822 case BuiltinType::OCLEvent:
823 Out <<
"@BT@OCLEvent";
825 case BuiltinType::OCLClkEvent:
826 Out <<
"@BT@OCLClkEvent";
828 case BuiltinType::OCLQueue:
829 Out <<
"@BT@OCLQueue";
831 case BuiltinType::OCLReserveID:
832 Out <<
"@BT@OCLReserveID";
834 case BuiltinType::OCLSampler:
835 Out <<
"@BT@OCLSampler";
837#define SVE_TYPE(Name, Id, SingletonId) \
838 case BuiltinType::Id: \
839 Out << "@BT@" << #Name; \
841#include "clang/Basic/AArch64ACLETypes.def"
842#define PPC_VECTOR_TYPE(Name, Id, Size) \
843 case BuiltinType::Id: \
844 Out << "@BT@" << #Name; \
846#include "clang/Basic/PPCTypes.def"
847#define RVV_TYPE(Name, Id, SingletonId) \
848 case BuiltinType::Id: \
849 Out << "@BT@" << Name; \
851#include "clang/Basic/RISCVVTypes.def"
852#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
853#include "clang/Basic/WebAssemblyReferenceTypes.def"
854#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
855 case BuiltinType::Id: \
856 Out << "@BT@" << #Name; \
858#include "clang/Basic/AMDGPUTypes.def"
859#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
860 case BuiltinType::Id: \
861 Out << "@BT@" << #Name; \
863#include "clang/Basic/HLSLIntangibleTypes.def"
864#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
865 case BuiltinType::Id: \
866 Out << "@BT@" << #Name; \
868#include "clang/Basic/HLSLPackedTypes.def"
869#define SPIRV_TYPE(Name, Id, SingletonId) \
870 case BuiltinType::Id: \
871 Out << "@BT@" << Name; \
873#include "clang/Basic/SPIRVTypes.def"
874 case BuiltinType::ShortAccum:
875 Out <<
"@BT@ShortAccum";
877 case BuiltinType::Accum:
880 case BuiltinType::LongAccum:
881 Out <<
"@BT@LongAccum";
883 case BuiltinType::UShortAccum:
884 Out <<
"@BT@UShortAccum";
886 case BuiltinType::UAccum:
889 case BuiltinType::ULongAccum:
890 Out <<
"@BT@ULongAccum";
892 case BuiltinType::ShortFract:
893 Out <<
"@BT@ShortFract";
895 case BuiltinType::Fract:
898 case BuiltinType::LongFract:
899 Out <<
"@BT@LongFract";
901 case BuiltinType::UShortFract:
902 Out <<
"@BT@UShortFract";
904 case BuiltinType::UFract:
907 case BuiltinType::ULongFract:
908 Out <<
"@BT@ULongFract";
910 case BuiltinType::SatShortAccum:
911 Out <<
"@BT@SatShortAccum";
913 case BuiltinType::SatAccum:
914 Out <<
"@BT@SatAccum";
916 case BuiltinType::SatLongAccum:
917 Out <<
"@BT@SatLongAccum";
919 case BuiltinType::SatUShortAccum:
920 Out <<
"@BT@SatUShortAccum";
922 case BuiltinType::SatUAccum:
923 Out <<
"@BT@SatUAccum";
925 case BuiltinType::SatULongAccum:
926 Out <<
"@BT@SatULongAccum";
928 case BuiltinType::SatShortFract:
929 Out <<
"@BT@SatShortFract";
931 case BuiltinType::SatFract:
932 Out <<
"@BT@SatFract";
934 case BuiltinType::SatLongFract:
935 Out <<
"@BT@SatLongFract";
937 case BuiltinType::SatUShortFract:
938 Out <<
"@BT@SatUShortFract";
940 case BuiltinType::SatUFract:
941 Out <<
"@BT@SatUFract";
943 case BuiltinType::SatULongFract:
944 Out <<
"@BT@SatULongFract";
946 case BuiltinType::BFloat16:
949 case BuiltinType::Ibm128:
950 Out <<
"@BT@__ibm128";
952 case BuiltinType::ObjCId:
955 case BuiltinType::ObjCClass:
958 case BuiltinType::ObjCSel:
961#define BUILTIN_TYPE(Id, SingletonId)
962#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
963#include "clang/AST/BuiltinTypes.def"
964 case BuiltinType::Dependent:
967 IgnoreResults =
true;
975 auto [Substitution, Inserted] =
976 TypeSubstitutions.try_emplace(
T.getTypePtr(), TypeSubstitutions.size());
978 Out <<
'S' << Substitution->second <<
'_';
982 if (
const PointerType *PT =
T->
getAs<PointerType>()) {
987 if (
const ObjCObjectPointerType *OPT =
T->
getAs<ObjCObjectPointerType>()) {
992 if (
const RValueReferenceType *RT =
T->
getAs<RValueReferenceType>()) {
997 if (
const ReferenceType *RT =
T->
getAs<ReferenceType>()) {
1002 if (
const FunctionProtoType *FT =
T->
getAs<FunctionProtoType>()) {
1004 VisitType(FT->getReturnType());
1006 for (
const auto &I : FT->param_types()) {
1011 if (FT->isVariadic())
1015 if (
const BlockPointerType *BT =
T->
getAs<BlockPointerType>()) {
1020 if (
const ComplexType *CT =
T->
getAs<ComplexType>()) {
1022 T = CT->getElementType();
1025 if (
const TagType *TT =
T->
getAs<TagType>()) {
1026 if (
const auto *ICNT = dyn_cast<InjectedClassNameType>(TT)) {
1027 T = ICNT->getDecl()->getCanonicalTemplateSpecializationType(Ctx);
1030 VisitTagDecl(TT->getDecl());
1034 if (
const ObjCInterfaceType *OIT =
T->
getAs<ObjCInterfaceType>()) {
1036 VisitObjCInterfaceDecl(OIT->getDecl());
1039 if (
const ObjCObjectType *OIT =
T->
getAs<ObjCObjectType>()) {
1041 VisitType(OIT->getBaseType());
1042 for (
auto *Prot : OIT->getProtocols())
1043 VisitObjCProtocolDecl(Prot);
1046 if (
const TemplateTypeParmType *TTP =
1048 Out <<
't' << TTP->getDepth() <<
'.' << TTP->getIndex();
1051 if (
const TemplateSpecializationType *Spec =
1052 T->
getAs<TemplateSpecializationType>()) {
1054 VisitTemplateName(Spec->getTemplateName());
1055 Out << Spec->template_arguments().size();
1056 for (
const auto &Arg : Spec->template_arguments())
1057 VisitTemplateArgument(Arg);
1060 if (
const DependentNameType *DNT =
T->
getAs<DependentNameType>()) {
1063 Out <<
':' << DNT->getIdentifier()->getName();
1066 if (
const auto *VT =
T->
getAs<VectorType>()) {
1068 Out << VT->getNumElements();
1069 T = VT->getElementType();
1072 if (
const auto *
const AT = dyn_cast<ArrayType>(
T)) {
1074 switch (AT->getSizeModifier()) {
1075 case ArraySizeModifier::Static:
1078 case ArraySizeModifier::Star:
1081 case ArraySizeModifier::Normal:
1085 if (
const auto *
const CAT = dyn_cast<ConstantArrayType>(
T))
1086 Out << CAT->getSize();
1088 T = AT->getElementType();
1098void USRGenerator::VisitTemplateParameterList(
1099 const TemplateParameterList *Params) {
1102 Out <<
'>' << Params->
size();
1103 for (TemplateParameterList::const_iterator P = Params->
begin(),
1104 PEnd = Params->
end();
1114 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
1115 if (NTTP->isParameterPack())
1118 VisitType(NTTP->getType());
1130void USRGenerator::VisitTemplateName(
TemplateName Name) {
1132 if (TemplateTemplateParmDecl *TTP =
1133 dyn_cast<TemplateTemplateParmDecl>(
Template)) {
1134 Out <<
't' << TTP->getDepth() <<
'.' << TTP->getIndex();
1145void USRGenerator::VisitTemplateArgument(
const TemplateArgument &Arg) {
1171 VisitTemplateArgument(P);
1195void USRGenerator::VisitUnresolvedUsingValueDecl(
1196 const UnresolvedUsingValueDecl *D) {
1197 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1205void USRGenerator::VisitUnresolvedUsingTypenameDecl(
1206 const UnresolvedUsingTypenameDecl *D) {
1207 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1215void USRGenerator::VisitConceptDecl(
const ConceptDecl *D) {
1216 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1223void USRGenerator::VisitMSGuidDecl(
const MSGuidDecl *D) {
1226 D->NamedDecl::printName(Out);
1229void USRGenerator::VisitTemplateParamObjectDecl(
1230 const TemplateParamObjectDecl *D) {
1243 StringRef CatSymDefinedIn,
1245 if (ClsSymDefinedIn.empty() && CatSymDefinedIn.empty())
1247 if (CatSymDefinedIn.empty()) {
1248 OS <<
"@M@" << ClsSymDefinedIn <<
'@';
1251 OS <<
"@CM@" << CatSymDefinedIn <<
'@';
1252 if (ClsSymDefinedIn != CatSymDefinedIn) {
1253 OS << ClsSymDefinedIn <<
'@';
1258 StringRef Cls, raw_ostream &OS, StringRef ExtSymDefinedIn,
1259 StringRef CategoryContextExtSymbolDefinedIn) {
1261 CategoryContextExtSymbolDefinedIn, OS);
1262 OS <<
"objc(cs)" << Cls;
1267 StringRef ClsSymDefinedIn,
1268 StringRef CatSymDefinedIn) {
1270 OS <<
"objc(cy)" << Cls <<
'@' << Cat;
1278 bool IsInstanceMethod,
1280 OS << (IsInstanceMethod ?
"(im)" :
"(cm)") << Sel;
1285 OS << (isClassProp ?
"(cpy)" :
"(py)") << Prop;
1289 StringRef ExtSymDefinedIn) {
1290 if (!ExtSymDefinedIn.empty())
1291 OS <<
"@M@" << ExtSymDefinedIn <<
'@';
1292 OS <<
"objc(pl)" << Prot;
1296 StringRef ExtSymDefinedIn) {
1297 if (!ExtSymDefinedIn.empty())
1298 OS <<
"@M@" << ExtSymDefinedIn;
1299 OS <<
"@E@" << EnumName;
1304 OS <<
'@' << EnumConstantName;
1324 if (
auto *ExternalSymAttr = CD->
getAttr<ExternalSourceSymbolAttr>()) {
1325 if (!ExternalSymAttr->getUSR().empty()) {
1326 llvm::raw_svector_ostream Out(Buf);
1327 Out << ExternalSymAttr->getUSR();
1333 return UG.ignoreResults();
1348 if (MacroName.empty())
1351 llvm::raw_svector_ostream Out(Buf);
1358 if (ShouldGenerateLocation)
1375 T =
T.getCanonicalType();
1377 USRGenerator UG(&Ctx, Buf, LangOpts);
1379 return UG.ignoreResults();
1404 OS <<
"@M@" << ModName;
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
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)
Print Loc including both the file and offset, if IncludeOffset is true.
static const ObjCCategoryDecl * getCategoryContext(const NamedDecl *D)
static void printQualifier(llvm::raw_ostream &Out, const LangOptions &LangOpts, NestedNameSpecifier NNS)
static bool printLocOffset(llvm::raw_ostream &OS, SourceLocation Loc, const SourceManager &SM)
Print only the offset part of Loc.
static StringRef GetExternalSourceContainer(const NamedDecl *D)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
static CanQualType getCanonicalType(QualType T)
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...
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
A simple visitor class that helps create declaration visitors.
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
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
bool isEmpty() const
Evaluates true when this declaration name is empty.
StringRef getName() const
The name of this FileEntry.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
QualType getReturnType() const
bool isVariadic() const
Whether this function is variadic.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isExternC() const
Determines whether this function is a function with external, C linkage.
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
StringRef getName() const
Return the actual identifier string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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.
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.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
bool isExternallyVisible() const
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false, bool PrintFinalScopeResOp=true) const
Print this nested name specifier to the given output stream.
void AddStructuralValue(const APValue &)
ObjCCategoryDecl - Represents a category declaration.
ObjCInterfaceDecl * getClassInterface()
bool IsClassExtension() const
const ObjCInterfaceDecl * getClassInterface() const
Selector getSelector() const
bool isInstanceMethod() const
ObjCInterfaceDecl * getClassInterface()
bool isClassProperty() const
ObjCPropertyDecl * getPropertyDecl() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getCanonicalType() const
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.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
bool isEmbeddedInDeclarator() const
True if this tag declaration is "embedded" (i.e., defined or declared for the very first time) in the...
TypedefNameDecl * getTypedefNameForAnonDecl() const
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
TagKind getTagKind() const
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.
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.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
const APValue & getValue() const
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isExtVectorType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
const T * getAs() const
Member-template getAs<specific type>'.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
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.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
std::pair< FileID, unsigned > FileIDAndOffset
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
U cast(CodeGen::Address addr)
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 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.
@ Plain
E.g., (anonymous enum)/(unnamed struct)/etc.
unsigned AnonymousTagNameStyle