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 case BuiltinType::ShortAccum:
862 Out <<
"@BT@ShortAccum";
864 case BuiltinType::Accum:
867 case BuiltinType::LongAccum:
868 Out <<
"@BT@LongAccum";
870 case BuiltinType::UShortAccum:
871 Out <<
"@BT@UShortAccum";
873 case BuiltinType::UAccum:
876 case BuiltinType::ULongAccum:
877 Out <<
"@BT@ULongAccum";
879 case BuiltinType::ShortFract:
880 Out <<
"@BT@ShortFract";
882 case BuiltinType::Fract:
885 case BuiltinType::LongFract:
886 Out <<
"@BT@LongFract";
888 case BuiltinType::UShortFract:
889 Out <<
"@BT@UShortFract";
891 case BuiltinType::UFract:
894 case BuiltinType::ULongFract:
895 Out <<
"@BT@ULongFract";
897 case BuiltinType::SatShortAccum:
898 Out <<
"@BT@SatShortAccum";
900 case BuiltinType::SatAccum:
901 Out <<
"@BT@SatAccum";
903 case BuiltinType::SatLongAccum:
904 Out <<
"@BT@SatLongAccum";
906 case BuiltinType::SatUShortAccum:
907 Out <<
"@BT@SatUShortAccum";
909 case BuiltinType::SatUAccum:
910 Out <<
"@BT@SatUAccum";
912 case BuiltinType::SatULongAccum:
913 Out <<
"@BT@SatULongAccum";
915 case BuiltinType::SatShortFract:
916 Out <<
"@BT@SatShortFract";
918 case BuiltinType::SatFract:
919 Out <<
"@BT@SatFract";
921 case BuiltinType::SatLongFract:
922 Out <<
"@BT@SatLongFract";
924 case BuiltinType::SatUShortFract:
925 Out <<
"@BT@SatUShortFract";
927 case BuiltinType::SatUFract:
928 Out <<
"@BT@SatUFract";
930 case BuiltinType::SatULongFract:
931 Out <<
"@BT@SatULongFract";
933 case BuiltinType::BFloat16:
936 case BuiltinType::Ibm128:
937 Out <<
"@BT@__ibm128";
939 case BuiltinType::ObjCId:
942 case BuiltinType::ObjCClass:
945 case BuiltinType::ObjCSel:
948#define BUILTIN_TYPE(Id, SingletonId)
949#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
950#include "clang/AST/BuiltinTypes.def"
951 case BuiltinType::Dependent:
954 IgnoreResults =
true;
962 auto [Substitution, Inserted] =
963 TypeSubstitutions.try_emplace(
T.getTypePtr(), TypeSubstitutions.size());
965 Out <<
'S' << Substitution->second <<
'_';
969 if (
const PointerType *PT =
T->
getAs<PointerType>()) {
974 if (
const ObjCObjectPointerType *OPT =
T->
getAs<ObjCObjectPointerType>()) {
979 if (
const RValueReferenceType *RT =
T->
getAs<RValueReferenceType>()) {
984 if (
const ReferenceType *RT =
T->
getAs<ReferenceType>()) {
989 if (
const FunctionProtoType *FT =
T->
getAs<FunctionProtoType>()) {
991 VisitType(FT->getReturnType());
993 for (
const auto &I : FT->param_types()) {
998 if (FT->isVariadic())
1002 if (
const BlockPointerType *BT =
T->
getAs<BlockPointerType>()) {
1007 if (
const ComplexType *CT =
T->
getAs<ComplexType>()) {
1009 T = CT->getElementType();
1012 if (
const TagType *TT =
T->
getAs<TagType>()) {
1013 if (
const auto *ICNT = dyn_cast<InjectedClassNameType>(TT)) {
1014 T = ICNT->getDecl()->getCanonicalTemplateSpecializationType(Ctx);
1017 VisitTagDecl(TT->getDecl());
1021 if (
const ObjCInterfaceType *OIT =
T->
getAs<ObjCInterfaceType>()) {
1023 VisitObjCInterfaceDecl(OIT->getDecl());
1026 if (
const ObjCObjectType *OIT =
T->
getAs<ObjCObjectType>()) {
1028 VisitType(OIT->getBaseType());
1029 for (
auto *Prot : OIT->getProtocols())
1030 VisitObjCProtocolDecl(Prot);
1033 if (
const TemplateTypeParmType *TTP =
1035 Out <<
't' << TTP->getDepth() <<
'.' << TTP->getIndex();
1038 if (
const TemplateSpecializationType *Spec =
1039 T->
getAs<TemplateSpecializationType>()) {
1041 VisitTemplateName(Spec->getTemplateName());
1042 Out << Spec->template_arguments().size();
1043 for (
const auto &Arg : Spec->template_arguments())
1044 VisitTemplateArgument(Arg);
1047 if (
const DependentNameType *DNT =
T->
getAs<DependentNameType>()) {
1050 Out <<
':' << DNT->getIdentifier()->getName();
1053 if (
const auto *VT =
T->
getAs<VectorType>()) {
1055 Out << VT->getNumElements();
1056 T = VT->getElementType();
1059 if (
const auto *
const AT = dyn_cast<ArrayType>(
T)) {
1061 switch (AT->getSizeModifier()) {
1062 case ArraySizeModifier::Static:
1065 case ArraySizeModifier::Star:
1068 case ArraySizeModifier::Normal:
1072 if (
const auto *
const CAT = dyn_cast<ConstantArrayType>(
T))
1073 Out << CAT->getSize();
1075 T = AT->getElementType();
1085void USRGenerator::VisitTemplateParameterList(
1086 const TemplateParameterList *Params) {
1089 Out <<
'>' << Params->
size();
1090 for (TemplateParameterList::const_iterator P = Params->
begin(),
1091 PEnd = Params->
end();
1101 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
1102 if (NTTP->isParameterPack())
1105 VisitType(NTTP->getType());
1117void USRGenerator::VisitTemplateName(
TemplateName Name) {
1119 if (TemplateTemplateParmDecl *TTP =
1120 dyn_cast<TemplateTemplateParmDecl>(
Template)) {
1121 Out <<
't' << TTP->getDepth() <<
'.' << TTP->getIndex();
1132void USRGenerator::VisitTemplateArgument(
const TemplateArgument &Arg) {
1158 VisitTemplateArgument(P);
1182void USRGenerator::VisitUnresolvedUsingValueDecl(
1183 const UnresolvedUsingValueDecl *D) {
1184 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1192void USRGenerator::VisitUnresolvedUsingTypenameDecl(
1193 const UnresolvedUsingTypenameDecl *D) {
1194 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1202void USRGenerator::VisitConceptDecl(
const ConceptDecl *D) {
1203 if (ShouldGenerateLocation(D) && GenLoc(D, isLocal(D)))
1210void USRGenerator::VisitMSGuidDecl(
const MSGuidDecl *D) {
1213 D->NamedDecl::printName(Out);
1216void USRGenerator::VisitTemplateParamObjectDecl(
1217 const TemplateParamObjectDecl *D) {
1230 StringRef CatSymDefinedIn,
1232 if (ClsSymDefinedIn.empty() && CatSymDefinedIn.empty())
1234 if (CatSymDefinedIn.empty()) {
1235 OS <<
"@M@" << ClsSymDefinedIn <<
'@';
1238 OS <<
"@CM@" << CatSymDefinedIn <<
'@';
1239 if (ClsSymDefinedIn != CatSymDefinedIn) {
1240 OS << ClsSymDefinedIn <<
'@';
1245 StringRef Cls, raw_ostream &OS, StringRef ExtSymDefinedIn,
1246 StringRef CategoryContextExtSymbolDefinedIn) {
1248 CategoryContextExtSymbolDefinedIn, OS);
1249 OS <<
"objc(cs)" << Cls;
1254 StringRef ClsSymDefinedIn,
1255 StringRef CatSymDefinedIn) {
1257 OS <<
"objc(cy)" << Cls <<
'@' << Cat;
1265 bool IsInstanceMethod,
1267 OS << (IsInstanceMethod ?
"(im)" :
"(cm)") << Sel;
1272 OS << (isClassProp ?
"(cpy)" :
"(py)") << Prop;
1276 StringRef ExtSymDefinedIn) {
1277 if (!ExtSymDefinedIn.empty())
1278 OS <<
"@M@" << ExtSymDefinedIn <<
'@';
1279 OS <<
"objc(pl)" << Prot;
1283 StringRef ExtSymDefinedIn) {
1284 if (!ExtSymDefinedIn.empty())
1285 OS <<
"@M@" << ExtSymDefinedIn;
1286 OS <<
"@E@" << EnumName;
1291 OS <<
'@' << EnumConstantName;
1311 if (
auto *ExternalSymAttr = CD->
getAttr<ExternalSourceSymbolAttr>()) {
1312 if (!ExternalSymAttr->getUSR().empty()) {
1313 llvm::raw_svector_ostream Out(Buf);
1314 Out << ExternalSymAttr->getUSR();
1320 return UG.ignoreResults();
1335 if (MacroName.empty())
1338 llvm::raw_svector_ostream Out(Buf);
1345 if (ShouldGenerateLocation)
1362 T =
T.getCanonicalType();
1364 USRGenerator UG(&Ctx, Buf, LangOpts);
1366 return UG.ignoreResults();
1391 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.
The JSON file list parser is used to communicate input to InstallAPI.
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