37 #include "llvm/ADT/ArrayRef.h" 38 #include "llvm/ADT/PointerIntPair.h" 39 #include "llvm/ADT/SmallVector.h" 40 #include "llvm/ADT/StringRef.h" 41 #include "llvm/Support/Casting.h" 42 #include "llvm/Support/ErrorHandling.h" 43 #include "llvm/Support/MathExtras.h" 44 #include "llvm/Support/VersionTuple.h" 45 #include "llvm/Support/raw_ostream.h" 53 using namespace clang;
59 #define DECL(DERIVED, BASE) static int n##DERIVED##s = 0; 60 #define ABSTRACT_DECL(DECL) 61 #include "clang/AST/DeclNodes.inc" 67 #define DECL(DERIVED, BASE) \ 68 static_assert(alignof(Decl) >= alignof(DERIVED##Decl), \ 69 "Alignment sufficient after objects prepended to " #DERIVED); 70 #define ABSTRACT_DECL(DECL) 71 #include "clang/AST/DeclNodes.inc" 77 static_assert(
sizeof(
unsigned) * 2 >=
alignof(
Decl),
78 "Decl won't be misaligned");
79 void *Start = Context.
Allocate(Size + Extra + 8);
80 void *
Result = (
char*)Start + 8;
82 unsigned *PrefixPtr = (
unsigned *)Result - 2;
95 assert(!
Parent || &
Parent->getParentASTContext() == &Ctx);
99 if (Ctx.getLangOpts().trackLocalOwningModule() || !
Parent) {
103 llvm::OffsetToAlignment(
sizeof(
Module *),
alignof(
Decl));
104 auto *Buffer =
reinterpret_cast<char *
>(
105 ::operator
new(ExtraAlign +
sizeof(
Module *) + Size + Extra, Ctx));
106 Buffer += ExtraAlign;
109 return new (Buffer)
Module*(ParentModule) + 1;
111 return ::operator
new(Size + Extra, Ctx);
114 Module *Decl::getOwningModuleSlow()
const {
125 default: llvm_unreachable(
"Declaration not in DeclNodes.inc!");
126 #define DECL(DERIVED, BASE) case DERIVED: return #DERIVED; 127 #define ABSTRACT_DECL(DECL) 128 #include "clang/AST/DeclNodes.inc" 133 InvalidDecl = Invalid;
134 assert(!isa<TagDecl>(
this) || !cast<TagDecl>(
this)->isCompleteDefinition());
139 if (!isa<ParmVarDecl>(
this)) {
148 if (
auto *DD = dyn_cast<DecompositionDecl>(
this)) {
149 for (
auto *Binding : DD->bindings()) {
150 Binding->setInvalidDecl();
157 default: llvm_unreachable(
"Declaration context not in DeclNodes.inc!");
158 #define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED; 159 #define ABSTRACT_DECL(DECL) 160 #include "clang/AST/DeclNodes.inc" 164 bool Decl::StatisticsEnabled =
false;
166 StatisticsEnabled =
true;
170 llvm::errs() <<
"\n*** Decl Stats:\n";
173 #define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s; 174 #define ABSTRACT_DECL(DECL) 175 #include "clang/AST/DeclNodes.inc" 176 llvm::errs() <<
" " << totalDecls <<
" decls total.\n";
179 #define DECL(DERIVED, BASE) \ 180 if (n##DERIVED##s > 0) { \ 181 totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \ 182 llvm::errs() << " " << n##DERIVED##s << " " #DERIVED " decls, " \ 183 << sizeof(DERIVED##Decl) << " each (" \ 184 << n##DERIVED##s * sizeof(DERIVED##Decl) \ 187 #define ABSTRACT_DECL(DECL) 188 #include "clang/AST/DeclNodes.inc" 190 llvm::errs() <<
"Total bytes = " << totalBytes <<
"\n";
195 #define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break; 196 #define ABSTRACT_DECL(DECL) 197 #include "clang/AST/DeclNodes.inc" 202 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(
this))
203 return TTP->isParameterPack();
204 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(
this))
205 return NTTP->isParameterPack();
206 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(
this))
207 return TTP->isParameterPack();
212 if (
const auto *Parm = dyn_cast<ParmVarDecl>(
this))
213 return Parm->isParameterPack();
219 if (
auto *FD = dyn_cast<FunctionDecl>(
this))
221 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(
this))
222 return FTD->getTemplatedDecl();
227 return isa<TemplateDecl>(
this);
231 if (
auto *FD = dyn_cast<FunctionDecl>(
this))
232 return FD->getDescribedFunctionTemplate();
233 else if (
auto *RD = dyn_cast<CXXRecordDecl>(
this))
234 return RD->getDescribedClassTemplate();
235 else if (
auto *VD = dyn_cast<VarDecl>(
this))
236 return VD->getDescribedVarTemplate();
237 else if (
auto *AD = dyn_cast<TypeAliasDecl>(
this))
238 return AD->getDescribedAliasTemplate();
248 if (
auto *AsDC = dyn_cast<DeclContext>(
this))
249 return AsDC->isDependentContext();
257 DC = DC->getParent())
258 if (DC->isFunctionOrMethod())
271 TheLoc = TheDecl->getLocation();
280 if (
const auto *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) {
282 DN->printQualifiedName(OS);
306 getMultipleDC()->LexicalDC = DC;
320 "hidden declaration has no owning module");
325 if (SemaDC == LexicalDC) {
328 auto *MDC =
new (Ctx) Decl::MultipleDC();
329 MDC->SemanticDC = SemaDC;
330 MDC->LexicalDC = LexicalDC;
340 if (!isa<TagDecl>(LDC))
349 if (
const auto *ND = dyn_cast<NamespaceDecl>(DC))
350 if (ND->isAnonymousNamespace())
362 if (
auto *TUD = dyn_cast<TranslationUnitDecl>(
this))
366 assert(DC &&
"This decl is not contained in a translation unit!");
370 assert(DC &&
"This decl is not contained in a translation unit!");
373 return cast<TranslationUnitDecl>(DC);
393 Align =
std::max(Align, I->getAlignment(Ctx));
427 for (
const auto *I :
redecls())
438 if (isa<TranslationUnitDecl>(
this) || isa<NamespaceDecl>(
this))
442 if (cast<Decl>(DC)->isModulePrivate())
444 if (isa<ExportDecl>(DC))
451 const Decl *Definition =
nullptr;
452 if (
auto *
ID = dyn_cast<ObjCInterfaceDecl>(
this)) {
453 Definition =
ID->getDefinition();
454 }
else if (
auto *PD = dyn_cast<ObjCProtocolDecl>(
this)) {
455 Definition = PD->getDefinition();
456 }
else if (
auto *TD = dyn_cast<TagDecl>(
this)) {
457 Definition = TD->getDefinition();
462 if (
auto *attr = Definition->
getAttr<ExternalSourceSymbolAttr>())
465 return dcd->
getAttr<ExternalSourceSymbolAttr>();
472 return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>();
476 if (
auto *AA = getAttr<AliasAttr>())
478 if (
auto *IFA = getAttr<IFuncAttr>())
487 StringRef RealizedPlatform = A->getPlatform()->getName();
489 return RealizedPlatform;
490 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
491 if (suffix != StringRef::npos)
492 return RealizedPlatform.slice(0, suffix);
493 return RealizedPlatform;
506 const AvailabilityAttr *A,
507 std::string *Message,
508 VersionTuple EnclosingVersion) {
509 if (EnclosingVersion.empty())
512 if (EnclosingVersion.empty())
515 StringRef ActualPlatform = A->getPlatform()->getName();
522 StringRef PrettyPlatformName
523 = AvailabilityAttr::getPrettyPlatformName(ActualPlatform);
525 if (PrettyPlatformName.empty())
526 PrettyPlatformName = ActualPlatform;
528 std::string HintMessage;
529 if (!A->getMessage().empty()) {
531 HintMessage += A->getMessage();
535 if (A->getUnavailable()) {
538 llvm::raw_string_ostream Out(*Message);
539 Out <<
"not available on " << PrettyPlatformName
547 if (!A->getIntroduced().empty() &&
548 EnclosingVersion < A->getIntroduced()) {
551 llvm::raw_string_ostream Out(*Message);
552 VersionTuple VTI(A->getIntroduced());
553 Out <<
"introduced in " << PrettyPlatformName <<
' ' 554 << VTI << HintMessage;
561 if (!A->getObsoleted().empty() && EnclosingVersion >= A->getObsoleted()) {
564 llvm::raw_string_ostream Out(*Message);
565 VersionTuple VTO(A->getObsoleted());
566 Out <<
"obsoleted in " << PrettyPlatformName <<
' ' 567 << VTO << HintMessage;
574 if (!A->getDeprecated().empty() && EnclosingVersion >= A->getDeprecated()) {
577 llvm::raw_string_ostream Out(*Message);
578 VersionTuple VTD(A->getDeprecated());
579 Out <<
"first deprecated in " << PrettyPlatformName <<
' ' 580 << VTD << HintMessage;
590 VersionTuple EnclosingVersion,
591 StringRef *RealizedPlatform)
const {
592 if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(
this))
593 return FTD->getTemplatedDecl()->getAvailability(Message, EnclosingVersion,
597 std::string ResultMessage;
599 for (
const auto *A :
attrs()) {
600 if (
const auto *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
605 ResultMessage = Deprecated->getMessage();
611 if (
const auto *Unavailable = dyn_cast<UnavailableAttr>(A)) {
613 *Message = Unavailable->getMessage();
617 if (
const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
619 Message, EnclosingVersion);
622 if (RealizedPlatform)
623 *RealizedPlatform = Availability->getPlatform()->getName();
630 ResultMessage.swap(*Message);
637 Message->swap(ResultMessage);
644 for (
const auto *A :
attrs()) {
645 if (
const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
648 if (!Availability->getIntroduced().empty())
649 return Availability->getIntroduced();
656 IsDefinition =
false;
659 if (
const auto *Var = dyn_cast<VarDecl>(
this)) {
660 if (Var->isThisDeclarationADefinition()) {
667 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(
this)) {
675 }
else if (isa<ObjCInterfaceDecl>(
this) &&
690 for (
const auto *A :
attrs()) {
691 if (isa<WeakImportAttr>(A))
694 if (
const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
707 case CXXDeductionGuide:
710 case ConstructorUsingShadow:
727 case NonTypeTemplateParm:
733 case ObjCCompatibleAlias:
739 case TemplateTypeParm:
743 case UnresolvedUsingTypename:
749 case UnresolvedUsingValue:
760 case ObjCAtDefsField:
773 case FunctionTemplate:
777 case TemplateTemplateParm:
778 case TypeAliasTemplate:
781 case OMPDeclareReduction:
792 case ObjCPropertyImpl:
794 case PragmaDetectMismatch:
797 case TranslationUnit:
802 case BuiltinTemplate:
803 case ClassTemplateSpecialization:
804 case ClassTemplatePartialSpecialization:
805 case ClassScopeFunctionSpecialization:
806 case VarTemplateSpecialization:
807 case VarTemplatePartialSpecialization:
808 case ObjCImplementation:
810 case ObjCCategoryImpl:
812 case OMPThreadPrivate:
813 case OMPCapturedExpr:
819 llvm_unreachable(
"Invalid DeclKind!");
823 assert(!HasAttrs &&
"Decl already contains attrs.");
826 assert(AttrBlank.empty() &&
"HasAttrs was wrong?");
833 if (!HasAttrs)
return;
840 assert(HasAttrs &&
"No attrs to get!");
847 #define DECL(NAME, BASE) 848 #define DECL_CONTEXT(NAME) \ 850 return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D)); 851 #define DECL_CONTEXT_BASE(NAME) 852 #include "clang/AST/DeclNodes.inc" 854 #define DECL(NAME, BASE) 855 #define DECL_CONTEXT_BASE(NAME) \ 856 if (DK >= first##NAME && DK <= last##NAME) \ 857 return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D)); 858 #include "clang/AST/DeclNodes.inc" 859 llvm_unreachable(
"a decl that inherits DeclContext isn't handled");
866 #define DECL(NAME, BASE) 867 #define DECL_CONTEXT(NAME) \ 869 return static_cast<NAME##Decl *>(const_cast<Decl *>(D)); 870 #define DECL_CONTEXT_BASE(NAME) 871 #include "clang/AST/DeclNodes.inc" 873 #define DECL(NAME, BASE) 874 #define DECL_CONTEXT_BASE(NAME) \ 875 if (DK >= first##NAME && DK <= last##NAME) \ 876 return static_cast<NAME##Decl *>(const_cast<Decl *>(D)); 877 #include "clang/AST/DeclNodes.inc" 878 llvm_unreachable(
"a decl that inherits DeclContext isn't handled");
885 if (
const auto *FD = dyn_cast<FunctionDecl>(
this)) {
887 if (FD->hasBody(Definition))
893 return Body->getSourceRange().getEnd();
898 bool Decl::AccessDeclContextSanity()
const {
908 if (isa<TranslationUnitDecl>(
this) ||
909 isa<TemplateTypeParmDecl>(
this) ||
910 isa<NonTypeTemplateParmDecl>(
this) ||
913 isa<StaticAssertDecl>(
this) ||
914 isa<BlockDecl>(
this) ||
917 isa<ParmVarDecl>(
this) ||
920 isa<CXXRecordDecl>(
this) ||
921 isa<ClassScopeFunctionSpecializationDecl>(
this))
925 "Access specifier is AS_none inside a record decl");
935 if (
const auto *D = dyn_cast<ValueDecl>(
this))
937 else if (
const auto *D = dyn_cast<TypedefNameDecl>(
this))
938 Ty = D->getUnderlyingType();
953 if (
getKind(D) == Decl::CXXMethod) {
954 auto *MD = cast<CXXMethodDecl>(D);
955 if (MD->getOverloadedOperator() == OO_Call &&
956 MD->getParent()->isLambda())
959 }
else if (
auto *FD = dyn_cast<FunctionDecl>(D))
961 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
963 else if (
auto *BD = dyn_cast<BlockDecl>(D))
965 else if (
auto *CD = dyn_cast<CapturedDecl>(D))
985 #define DECL(NAME, BASE) 986 #define DECL_CONTEXT(NAME) case Decl::NAME: 987 #define DECL_CONTEXT_BASE(NAME) 988 #include "clang/AST/DeclNodes.inc" 991 #define DECL(NAME, BASE) 992 #define DECL_CONTEXT_BASE(NAME) \ 993 if (D->getKind() >= Decl::first##NAME && \ 994 D->getKind() <= Decl::last##NAME) \ 996 #include "clang/AST/DeclNodes.inc" 1011 if (isa<FunctionDecl>(
this))
1012 if (getParent()->getRedeclContext()->isFileContext() &&
1013 getLexicalParent()->getRedeclContext()->isRecord())
1014 return getLexicalParent();
1020 return isNamespace() &&
1021 cast<NamespaceDecl>(
this)->isInline();
1028 const auto *ND = cast<NamespaceDecl>(
this);
1029 if (ND->isInline()) {
1030 return ND->getParent()->isStdNamespace();
1033 if (!getParent()->getRedeclContext()->isTranslationUnit())
1037 return II && II->
isStr(
"std");
1041 if (isFileContext())
1044 if (isa<ClassTemplatePartialSpecializationDecl>(
this))
1047 if (
const auto *Record = dyn_cast<CXXRecordDecl>(
this)) {
1048 if (Record->getDescribedClassTemplate())
1051 if (Record->isDependentLambda())
1055 if (
const auto *Function = dyn_cast<FunctionDecl>(
this)) {
1056 if (Function->getDescribedFunctionTemplate())
1061 if (cast<Decl>(
this)->getFriendObjectKind())
1062 return getLexicalParent()->isDependentContext();
1069 return getParent() && getParent()->isDependentContext();
1073 if (DeclKind == Decl::Enum)
1074 return !cast<EnumDecl>(
this)->isScoped();
1075 else if (DeclKind == Decl::LinkageSpec || DeclKind == Decl::Export)
1083 while (DC->
getDeclKind() != Decl::TranslationUnit) {
1085 return cast<LinkageSpecDecl>(DC)->getLanguage() ==
ID;
1097 while (DC->
getDeclKind() != Decl::TranslationUnit) {
1100 return cast<LinkageSpecDecl>(DC);
1111 if (getPrimaryContext() !=
this)
1112 return getPrimaryContext()->Encloses(DC);
1122 case Decl::TranslationUnit:
1123 case Decl::ExternCContext:
1124 case Decl::LinkageSpec:
1127 case Decl::Captured:
1128 case Decl::OMPDeclareReduction:
1132 case Decl::Namespace:
1134 return static_cast<NamespaceDecl *
>(
this)->getOriginalNamespace();
1136 case Decl::ObjCMethod:
1139 case Decl::ObjCInterface:
1140 if (
auto *Def = cast<ObjCInterfaceDecl>(
this)->getDefinition())
1144 case Decl::ObjCProtocol:
1145 if (
auto *Def = cast<ObjCProtocolDecl>(
this)->getDefinition())
1149 case Decl::ObjCCategory:
1152 case Decl::ObjCImplementation:
1153 case Decl::ObjCCategoryImpl:
1157 if (DeclKind >= Decl::firstTag && DeclKind <= Decl::lastTag) {
1160 auto *Tag = cast<TagDecl>(
this);
1165 if (
const auto *TagTy = dyn_cast<TagType>(Tag->getTypeForDecl())) {
1167 TagDecl *PossiblePartialDef = TagTy->getDecl();
1169 return PossiblePartialDef;
1171 assert(isa<InjectedClassNameType>(Tag->getTypeForDecl()));
1177 assert(DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction &&
1178 "Unknown DeclContext kind");
1187 if (DeclKind != Decl::Namespace) {
1188 Contexts.push_back(
this);
1195 Contexts.push_back(N);
1197 std::reverse(Contexts.begin(), Contexts.end());
1200 std::pair<Decl *, Decl *>
1202 bool FieldsAlreadyLoaded) {
1204 Decl *FirstNewDecl =
nullptr;
1205 Decl *PrevDecl =
nullptr;
1206 for (
auto *D : Decls) {
1207 if (FieldsAlreadyLoaded && isa<FieldDecl>(D))
1218 return std::make_pair(FirstNewDecl, PrevDecl);
1224 void DeclContext::reconcileExternalVisibleStorage()
const {
1225 assert(NeedToReconcileExternalVisibleStorage && LookupPtr);
1226 NeedToReconcileExternalVisibleStorage =
false;
1228 for (
auto &Lookup : *LookupPtr)
1229 Lookup.second.setHasExternalDecls();
1236 DeclContext::LoadLexicalDeclsFromExternalStorage()
const {
1238 assert(hasExternalLexicalStorage() && Source &&
"No external storage?");
1245 ExternalLexicalStorage =
false;
1253 bool FieldsAlreadyLoaded =
false;
1254 if (
const auto *RD = dyn_cast<RecordDecl>(
this))
1255 FieldsAlreadyLoaded = RD->LoadedFieldsFromExternalStorage;
1259 Decl *ExternalFirst, *ExternalLast;
1260 std::tie(ExternalFirst, ExternalLast) =
1261 BuildDeclChain(Decls, FieldsAlreadyLoaded);
1262 ExternalLast->NextInContextAndBits.setPointer(FirstDecl);
1263 FirstDecl = ExternalFirst;
1265 LastDecl = ExternalLast;
1274 if (!(Map = DC->LookupPtr))
1275 Map = DC->CreateStoredDeclsMap(Context);
1276 if (DC->NeedToReconcileExternalVisibleStorage)
1277 DC->reconcileExternalVisibleStorage();
1279 (*Map)[Name].removeExternalDecls();
1290 if (!(Map = DC->LookupPtr))
1291 Map = DC->CreateStoredDeclsMap(Context);
1292 if (DC->NeedToReconcileExternalVisibleStorage)
1293 DC->reconcileExternalVisibleStorage();
1306 for (
unsigned I = 0, N = Decls.size(); I != N; ++I)
1309 Skip.push_back(Decls.size());
1312 unsigned SkipPos = 0;
1313 for (
unsigned I = 0, N = Decls.size(); I != N; ++I) {
1314 if (I == Skip[SkipPos])
1321 for (
auto *D : Decls) {
1333 if (hasExternalLexicalStorage())
1334 LoadLexicalDeclsFromExternalStorage();
1339 if (hasExternalLexicalStorage())
1340 LoadLexicalDeclsFromExternalStorage();
1351 if (hasExternalLexicalStorage())
1352 LoadLexicalDeclsFromExternalStorage();
1353 return containsDecl(D);
1373 if (isa<ClassTemplateSpecializationDecl>(D))
1375 if (
auto *FD = dyn_cast<FunctionDecl>(D))
1376 if (FD->isFunctionTemplateSpecialization())
1384 "decl being removed from non-lexical context");
1386 "decl is not in decls list");
1389 if (D == FirstDecl) {
1391 FirstDecl = LastDecl =
nullptr;
1395 for (
Decl *I = FirstDecl;
true; I = I->NextInContextAndBits.getPointer()) {
1396 assert(I &&
"decl not found in linked list");
1397 if (I->NextInContextAndBits.getPointer() == D) {
1399 if (D == LastDecl) LastDecl = I;
1409 if (isa<NamedDecl>(D)) {
1410 auto *ND = cast<NamedDecl>(D);
1418 if (!ND->getDeclName())
1425 StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
1426 assert(Pos != Map->end() &&
"no lookup entry for decl");
1427 if (Pos->second.getAsVector() || Pos->second.getAsDecl() == ND)
1428 Pos->second.remove(ND);
1430 }
while (DC->isTransparentContext() && (DC = DC->getParent()));
1436 "Decl inserted into wrong lexical context");
1438 "Decl already inserted into a DeclContext");
1441 LastDecl->NextInContextAndBits.setPointer(D);
1444 FirstDecl = LastDecl = D;
1449 if (
auto *Record = dyn_cast<CXXRecordDecl>(
this))
1450 Record->addedMember(D);
1455 if (
auto *Import = dyn_cast<ImportDecl>(D))
1463 if (
auto *ND = dyn_cast<NamedDecl>(D))
1464 ND->getDeclContext()->getPrimaryContext()->
1465 makeDeclVisibleInContextWithFlags(ND,
false,
true);
1471 if (
auto *ND = dyn_cast<NamedDecl>(D))
1472 ND->getDeclContext()->getPrimaryContext()->
1473 makeDeclVisibleInContextWithFlags(ND,
true,
true);
1484 assert(
this == getPrimaryContext() &&
"buildLookup called on non-primary DC");
1486 if (!HasLazyLocalLexicalLookups && !HasLazyExternalLexicalLookups)
1490 collectAllContexts(Contexts);
1492 if (HasLazyExternalLexicalLookups) {
1493 HasLazyExternalLexicalLookups =
false;
1494 for (
auto *DC : Contexts) {
1495 if (DC->hasExternalLexicalStorage())
1496 HasLazyLocalLexicalLookups |=
1497 DC->LoadLexicalDeclsFromExternalStorage();
1500 if (!HasLazyLocalLexicalLookups)
1504 for (
auto *DC : Contexts)
1505 buildLookupImpl(DC, hasExternalVisibleStorage());
1508 HasLazyLocalLexicalLookups =
false;
1516 void DeclContext::buildLookupImpl(
DeclContext *DCtx,
bool Internal) {
1526 if (
auto *ND = dyn_cast<NamedDecl>(D))
1528 (!ND->isFromASTFile() ||
1529 (isTranslationUnit() &&
1530 !getParentASTContext().getLangOpts().CPlusPlus)))
1531 makeDeclVisibleInContextImpl(ND, Internal);
1536 if (
auto *InnerCtx = dyn_cast<DeclContext>(D))
1537 if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
1538 buildLookupImpl(InnerCtx, Internal);
1542 NamedDecl *
const DeclContextLookupResult::SingleElementDummyList =
nullptr;
1546 assert(DeclKind != Decl::LinkageSpec && DeclKind != Decl::Export &&
1547 "should not perform lookups into transparent contexts");
1549 const DeclContext *PrimaryContext = getPrimaryContext();
1550 if (PrimaryContext !=
this)
1551 return PrimaryContext->
lookup(Name);
1558 (void)cast<Decl>(
this)->getMostRecentDecl();
1560 if (hasExternalVisibleStorage()) {
1561 assert(Source &&
"external visible storage but no external source?");
1563 if (NeedToReconcileExternalVisibleStorage)
1564 reconcileExternalVisibleStorage();
1568 if (HasLazyLocalLexicalLookups || HasLazyExternalLexicalLookups)
1570 Map =
const_cast<DeclContext*
>(
this)->buildLookup();
1573 Map = CreateStoredDeclsMap(getParentASTContext());
1576 std::pair<StoredDeclsMap::iterator, bool> R =
1578 if (!R.second && !R.first->second.hasExternalDecls())
1579 return R.first->second.getLookupResult();
1583 StoredDeclsMap::iterator I = Map->find(Name);
1584 if (I != Map->end())
1585 return I->second.getLookupResult();
1593 if (HasLazyLocalLexicalLookups || HasLazyExternalLexicalLookups)
1594 Map =
const_cast<DeclContext*
>(
this)->buildLookup();
1599 StoredDeclsMap::iterator I = Map->find(Name);
1600 if (I == Map->end())
1603 return I->second.getLookupResult();
1608 assert(DeclKind != Decl::LinkageSpec && DeclKind != Decl::Export &&
1609 "should not perform lookups into transparent contexts");
1611 DeclContext *PrimaryContext = getPrimaryContext();
1612 if (PrimaryContext !=
this)
1615 loadLazyLocalLexicalLookups();
1620 StoredDeclsMap::iterator I = Map->find(Name);
1621 return I != Map->end() ? I->second.getLookupResult()
1628 void DeclContext::loadLazyLocalLexicalLookups() {
1629 if (HasLazyLocalLexicalLookups) {
1631 collectAllContexts(Contexts);
1632 for (
auto *Context : Contexts)
1633 buildLookupImpl(Context, hasExternalVisibleStorage());
1634 HasLazyLocalLexicalLookups =
false;
1644 if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
1646 Results.insert(Results.end(), LookupResults.
begin(), LookupResults.
end());
1652 if (Name && !HasLazyLocalLexicalLookups && !HasLazyExternalLexicalLookups) {
1654 StoredDeclsMap::iterator Pos = Map->find(Name);
1655 if (Pos != Map->end()) {
1656 Results.insert(Results.end(),
1657 Pos->second.getLookupResult().begin(),
1658 Pos->second.getLookupResult().end());
1669 if (
auto *ND = dyn_cast<NamedDecl>(D))
1670 if (ND->getDeclName() == Name)
1671 Results.push_back(ND);
1696 OutermostRD = cast<RecordDecl>(DC);
1704 if (!isFileContext())
1712 if (!NS || !NS->isInline())
1721 DeclContext *PrimaryDC = this->getPrimaryContext();
1725 PrimaryDC->makeDeclVisibleInContextWithFlags(D,
false, PrimaryDC == DeclDC);
1728 void DeclContext::makeDeclVisibleInContextWithFlags(
NamedDecl *D,
bool Internal,
1730 assert(
this == getPrimaryContext() &&
"expected a primary DC");
1732 if (!isLookupContext()) {
1733 if (isTransparentContext())
1734 getParent()->getPrimaryContext()
1735 ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
1751 if (LookupPtr || hasExternalVisibleStorage() ||
1753 (getParentASTContext().getLangOpts().CPlusPlus ||
1754 !isTranslationUnit()))) {
1759 makeDeclVisibleInContextImpl(D, Internal);
1761 HasLazyLocalLexicalLookups =
true;
1766 if (isTransparentContext() || isInlineNamespace())
1767 getParent()->getPrimaryContext()->
1768 makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
1770 auto *DCAsDecl = cast<Decl>(
this);
1772 if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined()))
1774 L->AddedVisibleDecl(
this, D);
1777 void DeclContext::makeDeclVisibleInContextImpl(
NamedDecl *D,
bool Internal) {
1782 Map = CreateStoredDeclsMap(*C);
1791 if (hasExternalVisibleStorage() &&
1793 Source->FindExternalVisibleDeclsByName(
this, D->
getDeclName());
1808 if (DeclNameEntries.
isNull()) {
1824 return cast<UsingDirectiveDecl>(*I);
1841 assert(!LookupPtr &&
"context already has a decls map");
1842 assert(getPrimaryContext() ==
this &&
1843 "creating decls map on non-primary context");
1846 bool Dependent = isDependentContext();
1851 M->Previous = C.LastSDM;
1852 C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
1857 void ASTContext::ReleaseDeclContextMaps() {
1867 llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous;
1874 Map = Next.getPointer();
1875 Dependent = Next.getInt();
1883 &&
"cannot iterate dependent diagnostics of non-dependent context");
1885 if (!Parent->LookupPtr)
1886 Parent->CreateStoredDeclsMap(C);
1899 DD->NextDiagnostic = Map->FirstDiagnostic;
1900 Map->FirstDiagnostic = DD;
static StringRef getRealizedPlatform(const AvailabilityAttr *A, const ASTContext &Context)
Defines the clang::ASTContext interface.
Represents a function declaration or definition.
void setHasExternalDecls()
AttrVec & getDeclAttrs(const Decl *D)
Retrieve the attributes for the given declaration.
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl *> &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled...
static DeclContext * castToDeclContext(const Decl *)
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
static bool shouldBeHidden(NamedDecl *D)
shouldBeHidden - Determine whether a declaration which was declared within its semantic context shoul...
A (possibly-)qualified type.
bool isBlockPointerType() const
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
const char * getDeclKindName() const
llvm::PointerIntPair< Decl *, 2, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
void AddSubsequentDecl(NamedDecl *D)
AddSubsequentDecl - This is called on the second and later decl when it is not a redeclaration to mer...
virtual void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl *> &Result)
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
static Decl * castFromDeclContext(const DeclContext *)
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
static bool isLinkageSpecContext(const DeclContext *DC, LinkageSpecDecl::LanguageIDs ID)
Stmt - This represents one statement.
FunctionType - C99 6.7.5.3 - Function Declarators.
C Language Family Type Representation.
const char * getDeclKindName() const
Decl - This represents one declaration (or definition), e.g.
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
Defines the C++ template declaration subclasses.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
Defines types useful for describing an Objective-C runtime.
Represent a C++ namespace.
const TargetInfo & getTargetInfo() const
unsigned getIdentifierNamespace() const
static Decl * getNonClosureContext(T *D)
Starting at a given context (a Decl or DeclContext), look for a code context that is not a closure (a...
const DeclContext * getParentFunctionOrMethod() const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext...
unsigned Access
Access - Used by C++ decls for the access specifier.
bool HandleRedeclaration(NamedDecl *D, bool IsKnownNewer)
HandleRedeclaration - If this is a redeclaration of an existing decl, replace the old one with D and ...
bool hasOwningModule() const
Is this declaration owned by some module?
ASTMutationListener * getASTMutationListener() const
const T * getAs() const
Member-template getAs<specific type>'.
bool hasLocalOwningModuleStorage() const
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
bool isInvalidDecl() const
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
bool isParameterPack() const
Whether this declaration is a parameter pack.
void removeDecl(Decl *D)
Removes a declaration from this context.
bool hasWeakClassImport() const
Does this runtime support weakly importing classes?
Types, declared with 'struct foo', typedefs, etc.
bool isLexicallyWithinFunctionOrMethod() const
Returns true if this declaration lexically is inside a function.
Represents a struct/union/class.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
One of these records is kept for each identifier that is lexed.
bool isInAnonymousNamespace() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl *> Decls)
QualType getPointeeType() const
void print(raw_ostream &OS, const SourceManager &SM) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
The results of name lookup within a DeclContext.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Describes a module or submodule.
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)
Update an out-of-date identifier.
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name)
Find all declarations with the given name in the given context, and add them to the context by callin...
Namespaces, declared with 'namespace foo {}'.
bool isReferenced() const
Whether any declaration of this entity was referenced.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
ASTContext & getASTContext() const
void eraseDeclAttrs(const Decl *D)
Erase the attributes corresponding to the given declaration.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Labels, declared with 'x:' and referenced with 'goto x'.
void setLocalOwningModule(Module *M)
Represents a linkage specification.
bool isExported() const
Whether this declaration is exported (by virtue of being lexically within an ExportDecl or by being a...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
AvailabilityResult
Captures the result of checking the availability of a declaration.
Decl * getNextDeclInContext()
bool canBeWeakImported(bool &IsDefinition) const
Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the...
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
llvm::iterator_range< udir_iterator > udir_range
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible. ...
void removeExternalDecls()
Remove any declarations which were imported from an external AST source.
bool isInlineNamespace() const
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
const Attr * getDefiningAttr() const
Return this declaration's defining attribute if it has one.
Defines the clang::LangOptions interface.
static unsigned getIdentifierNamespaceForKind(Kind DK)
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
This declaration is an OpenMP user defined reduction construction.
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
bool isFileContext() const
DeclContext * getDeclContext()
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isFunctionOrMethod() const
clang::ObjCRuntime ObjCRuntime
This declaration has an owning module, and is visible when that module is imported.
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl, 0 if there are none.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
void collectAllContexts(SmallVectorImpl< DeclContext *> &Contexts)
Collects all of the declaration contexts that are semantically connected to this declaration context...
SourceLocation getEnd() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
The result type of a method or function.
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
virtual void DeclarationMarkedUsed(const Decl *D)
A declaration is marked used which was not previously marked used.
Abstract interface for external sources of AST nodes.
bool isTemplateDecl() const
returns true if this declaration is a template
Decl::Kind getDeclKind() const
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContext::lookup_result getLookupResult()
getLookupResult - Return an array of all the decls that this list represents.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
Encodes a location in the source.
Members, declared with object declarations within tag definitions.
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
decl_iterator decls_begin() const
Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
bool isStdNamespace() const
This file defines OpenMP nodes for declarative directives.
void print(raw_ostream &OS) const override
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
UsingDirectiveDecl * operator*() const
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
An array of decls optimized for the common case of only containing one entry.
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
void * Allocate(size_t Size, unsigned Align=8) const
decl_iterator - Iterates through the declarations stored within this context.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Dataflow Directional Tag Classes.
void updateOutOfDate(IdentifierInfo &II) const
Update a potentially out-of-date declaration.
bool isValid() const
Return true if this is a valid SourceLocation object.
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
The base class of all kinds of template declarations (e.g., class, function, etc.).
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
DeclarationName - The name of a declaration.
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks, lambdas, etc.
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
A dependently-generated diagnostic.
static DependentDiagnostic * Create(ASTContext &Context, DeclContext *Parent, AccessNonce _, SourceLocation Loc, bool IsMemberAccess, AccessSpecifier AS, NamedDecl *TargetDecl, CXXRecordDecl *NamingClass, QualType BaseObjectType, const PartialDiagnostic &PDiag)
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
LanguageIDs
Represents the language in a linkage specification.
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
void setOnlyValue(NamedDecl *ND)
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
const LinkageSpecDecl * getExternCContext() const
Retrieve the nearest enclosing C linkage specification context.
void addDecl(Decl *D)
Add the declaration D into this context.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Defines the clang::SourceLocation class and associated facilities.
DeclContextLookupResult lookup_result
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl *> Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
static bool classof(const Decl *D)
Defines the clang::TargetInfo interface.
ASTContext & getParentASTContext() const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Kind
Lists the kind of concrete classes of Decl.
__DEVICE__ int max(int __a, int __b)
The top declaration context.
static void DestroyAll(StoredDeclsMap *Map, bool Dependent)
NamedDecl * getMostRecentDecl()
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
static void EnableStatistics()
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined...
void setLexicalDeclContext(DeclContext *DC)
This represents a decl that may have a name.
bool isTranslationUnit() const
void setAccess(AccessSpecifier AS)
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration...
Represents C++ using-directive.
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity, such as 'alias' or 'ifunc'.
bool isFunctionPointerType() const
void addedLocalImportDecl(ImportDecl *Import)
Notify the AST context that a new import declaration has been parsed or implicitly created within thi...
bool isInStdNamespace() const
TranslationUnitDecl * getTranslationUnitDecl()
const LangOptions & getLangOpts() const
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
Attr - This represents one attribute.
static AvailabilityResult CheckAvailability(ASTContext &Context, const AvailabilityAttr *A, std::string *Message, VersionTuple EnclosingVersion)
Determine the availability of the given declaration based on the target platform. ...
bool isBeingDefined() const
Return true if this decl is currently being defined.
This declaration is a using declaration.
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context, meaning that the members declared in this context are semantically declared in the nearest enclosing non-transparent (opaque) context but are lexically declared in this context.