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#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
810 case BuiltinType::Id: \
811 Out << "@BT@" << #Suffix << "_" << #ImgType; \
813#include "clang/Basic/OpenCLImageTypes.def"
814#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
815 case BuiltinType::Id: \
816 Out << "@BT@" << #ExtType; \
818#include "clang/Basic/OpenCLExtensionTypes.def"
819 case BuiltinType::OCLEvent:
820 Out <<
"@BT@OCLEvent";
822 case BuiltinType::OCLClkEvent:
823 Out <<
"@BT@OCLClkEvent";
825 case BuiltinType::OCLQueue:
826 Out <<
"@BT@OCLQueue";
828 case BuiltinType::OCLReserveID:
829 Out <<
"@BT@OCLReserveID";
831 case BuiltinType::OCLSampler:
832 Out <<
"@BT@OCLSampler";
834#define SVE_TYPE(Name, Id, SingletonId) \
835 case BuiltinType::Id: \
836 Out << "@BT@" << #Name; \
838#include "clang/Basic/AArch64ACLETypes.def"
839#define PPC_VECTOR_TYPE(Name, Id, Size) \
840 case BuiltinType::Id: \
841 Out << "@BT@" << #Name; \
843#include "clang/Basic/PPCTypes.def"
844#define RVV_TYPE(Name, Id, SingletonId) \
845 case BuiltinType::Id: \
846 Out << "@BT@" << Name; \
848#include "clang/Basic/RISCVVTypes.def"
849#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
850#include "clang/Basic/WebAssemblyReferenceTypes.def"
851#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
852 case BuiltinType::Id: \
853 Out << "@BT@" << #Name; \
855#include "clang/Basic/AMDGPUTypes.def"
856#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
857 case BuiltinType::Id: \
858 Out << "@BT@" << #Name; \
860#include "clang/Basic/HLSLIntangibleTypes.def"
861#define SPIRV_TYPE(Name, Id, SingletonId) \
862 case BuiltinType::Id: \
863 Out << "@BT@" << Name; \
865#include "clang/Basic/SPIRVTypes.def"
866 case BuiltinType::ShortAccum:
867 Out <<
"@BT@ShortAccum";
869 case BuiltinType::Accum:
872 case BuiltinType::LongAccum:
873 Out <<
"@BT@LongAccum";
875 case BuiltinType::UShortAccum:
876 Out <<
"@BT@UShortAccum";
878 case BuiltinType::UAccum:
881 case BuiltinType::ULongAccum:
882 Out <<
"@BT@ULongAccum";
884 case BuiltinType::ShortFract:
885 Out <<
"@BT@ShortFract";
887 case BuiltinType::Fract:
890 case BuiltinType::LongFract:
891 Out <<
"@BT@LongFract";
893 case BuiltinType::UShortFract:
894 Out <<
"@BT@UShortFract";
896 case BuiltinType::UFract:
899 case BuiltinType::ULongFract:
900 Out <<
"@BT@ULongFract";
902 case BuiltinType::SatShortAccum:
903 Out <<
"@BT@SatShortAccum";
905 case BuiltinType::SatAccum:
906 Out <<
"@BT@SatAccum";
908 case BuiltinType::SatLongAccum:
909 Out <<
"@BT@SatLongAccum";
911 case BuiltinType::SatUShortAccum:
912 Out <<
"@BT@SatUShortAccum";
914 case BuiltinType::SatUAccum:
915 Out <<
"@BT@SatUAccum";
917 case BuiltinType::SatULongAccum:
918 Out <<
"@BT@SatULongAccum";
920 case BuiltinType::SatShortFract:
921 Out <<
"@BT@SatShortFract";
923 case BuiltinType::SatFract:
924 Out <<
"@BT@SatFract";
926 case BuiltinType::SatLongFract:
927 Out <<
"@BT@SatLongFract";
929 case BuiltinType::SatUShortFract:
930 Out <<
"@BT@SatUShortFract";
932 case BuiltinType::SatUFract:
933 Out <<
"@BT@SatUFract";
935 case BuiltinType::SatULongFract:
936 Out <<
"@BT@SatULongFract";
938 case BuiltinType::BFloat16:
941 case BuiltinType::Ibm128:
942 Out <<
"@BT@__ibm128";
944 case BuiltinType::ObjCId:
947 case BuiltinType::ObjCClass:
950 case BuiltinType::ObjCSel:
953#define BUILTIN_TYPE(Id, SingletonId)
954#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
955#include "clang/AST/BuiltinTypes.def"
956 case BuiltinType::Dependent:
959 IgnoreResults =
true;
967 auto [Substitution, Inserted] =
968 TypeSubstitutions.try_emplace(
T.getTypePtr(), TypeSubstitutions.size());
970 Out <<
'S' << Substitution->second <<
'_';
974 if (
const PointerType *PT =
T->
getAs<PointerType>()) {
979 if (
const ObjCObjectPointerType *OPT =
T->
getAs<ObjCObjectPointerType>()) {
984 if (
const RValueReferenceType *RT =
T->
getAs<RValueReferenceType>()) {
989 if (
const ReferenceType *RT =
T->
getAs<ReferenceType>()) {
994 if (
const FunctionProtoType *FT =
T->
getAs<FunctionProtoType>()) {
996 VisitType(FT->getReturnType());
998 for (
const auto &I : FT->param_types()) {
1003 if (FT->isVariadic())
1007 if (
const BlockPointerType *BT =
T->
getAs<BlockPointerType>()) {
1012 if (
const ComplexType *CT =
T->
getAs<ComplexType>()) {
1014 T = CT->getElementType();
1017 if (
const TagType *TT =
T->
getAs<TagType>()) {
1018 if (
const auto *ICNT = dyn_cast<InjectedClassNameType>(TT)) {
1019 T = ICNT->getDecl()->getCanonicalTemplateSpecializationType(Ctx);
1022 VisitTagDecl(TT->getDecl());
1026 if (
const ObjCInterfaceType *OIT =
T->
getAs<ObjCInterfaceType>()) {
1028 VisitObjCInterfaceDecl(OIT->getDecl());
1031 if (
const ObjCObjectType *OIT =
T->
getAs<ObjCObjectType>()) {
1033 VisitType(OIT->getBaseType());
1034 for (
auto *Prot : OIT->getProtocols())
1035 VisitObjCProtocolDecl(Prot);
1038 if (
const TemplateTypeParmType *TTP =
1040 Out <<
't' << TTP->getDepth() <<
'.' << TTP->getIndex();
1043 if (
const TemplateSpecializationType *Spec =
1044 T->
getAs<TemplateSpecializationType>()) {
1046 VisitTemplateName(Spec->getTemplateName());
1047 Out << Spec->template_arguments().size();
1048 for (
const auto &Arg : Spec->template_arguments())
1049 VisitTemplateArgument(Arg);
1052 if (
const DependentNameType *DNT =
T->
getAs<DependentNameType>()) {
1055 Out <<
':' << DNT->getIdentifier()->getName();
1058 if (
const auto *VT =
T->
getAs<VectorType>()) {
1060 Out << VT->getNumElements();
1061 T = VT->getElementType();
1064 if (
const auto *
const AT = dyn_cast<ArrayType>(
T)) {
1066 switch (AT->getSizeModifier()) {
1067 case ArraySizeModifier::Static:
1070 case ArraySizeModifier::Star:
1073 case ArraySizeModifier::Normal:
1077 if (
const auto *
const CAT = dyn_cast<ConstantArrayType>(
T))
1078 Out << CAT->getSize();
1080 T = AT->getElementType();
1090void USRGenerator::VisitTemplateParameterList(
1091 const TemplateParameterList *Params) {
1094 Out <<
'>' << Params->
size();
1095 for (TemplateParameterList::const_iterator P = Params->
begin(),
1096 PEnd = Params->
end();
1106 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
1107 if (NTTP->isParameterPack())
1110 VisitType(NTTP->getType());
1122void USRGenerator::VisitTemplateName(
TemplateName Name) {
1124 if (TemplateTemplateParmDecl *TTP =
1125 dyn_cast<TemplateTemplateParmDecl>(
Template)) {
1126 Out <<
't' << TTP->getDepth() <<
'.' << TTP->getIndex();
1137void USRGenerator::VisitTemplateArgument(
const TemplateArgument &Arg) {
1163 VisitTemplateArgument(P);
1187void USRGenerator::VisitUnresolvedUsingValueDecl(
1188 const UnresolvedUsingValueDecl *D) {
1189 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1197void USRGenerator::VisitUnresolvedUsingTypenameDecl(
1198 const UnresolvedUsingTypenameDecl *D) {
1199 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1207void USRGenerator::VisitConceptDecl(
const ConceptDecl *D) {
1208 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1215void USRGenerator::VisitMSGuidDecl(
const MSGuidDecl *D) {
1218 D->NamedDecl::printName(Out);
1221void USRGenerator::VisitTemplateParamObjectDecl(
1222 const TemplateParamObjectDecl *D) {
1235 StringRef CatSymDefinedIn,
1237 if (ClsSymDefinedIn.empty() && CatSymDefinedIn.empty())
1239 if (CatSymDefinedIn.empty()) {
1240 OS <<
"@M@" << ClsSymDefinedIn <<
'@';
1243 OS <<
"@CM@" << CatSymDefinedIn <<
'@';
1244 if (ClsSymDefinedIn != CatSymDefinedIn) {
1245 OS << ClsSymDefinedIn <<
'@';
1250 StringRef Cls, raw_ostream &OS, StringRef ExtSymDefinedIn,
1251 StringRef CategoryContextExtSymbolDefinedIn) {
1253 CategoryContextExtSymbolDefinedIn, OS);
1254 OS <<
"objc(cs)" << Cls;
1259 StringRef ClsSymDefinedIn,
1260 StringRef CatSymDefinedIn) {
1262 OS <<
"objc(cy)" << Cls <<
'@' << Cat;
1270 bool IsInstanceMethod,
1272 OS << (IsInstanceMethod ?
"(im)" :
"(cm)") << Sel;
1277 OS << (isClassProp ?
"(cpy)" :
"(py)") << Prop;
1281 StringRef ExtSymDefinedIn) {
1282 if (!ExtSymDefinedIn.empty())
1283 OS <<
"@M@" << ExtSymDefinedIn <<
'@';
1284 OS <<
"objc(pl)" << Prot;
1288 StringRef ExtSymDefinedIn) {
1289 if (!ExtSymDefinedIn.empty())
1290 OS <<
"@M@" << ExtSymDefinedIn;
1291 OS <<
"@E@" << EnumName;
1296 OS <<
'@' << EnumConstantName;
1316 if (
auto *ExternalSymAttr = CD->
getAttr<ExternalSourceSymbolAttr>()) {
1317 if (!ExternalSymAttr->getUSR().empty()) {
1318 llvm::raw_svector_ostream Out(Buf);
1319 Out << ExternalSymAttr->getUSR();
1325 return UG.ignoreResults();
1340 if (MacroName.empty())
1343 llvm::raw_svector_ostream Out(Buf);
1350 if (ShouldGenerateLocation)
1367 T =
T.getCanonicalType();
1369 USRGenerator UG(&Ctx, Buf, LangOpts);
1371 return UG.ignoreResults();
1396 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