31 #include "llvm/Support/raw_ostream.h"
33 using namespace clang;
39 #define DECL(DERIVED, BASE) static int n##DERIVED##s = 0;
40 #define ABSTRACT_DECL(DECL)
41 #include "clang/AST/DeclNodes.inc"
47 #define DECL(DERIVED, BASE) \
48 static_assert(alignof(Decl) >= alignof(DERIVED##Decl), \
49 "Alignment sufficient after objects prepended to " #DERIVED);
50 #define ABSTRACT_DECL(DECL)
51 #include "clang/AST/DeclNodes.inc"
57 static_assert(
sizeof(
unsigned) * 2 >=
alignof(
Decl),
58 "Decl won't be misaligned");
60 void *
Result = (
char*)Start + 8;
62 unsigned *PrefixPtr = (
unsigned *)Result - 2;
75 assert(!Parent || &Parent->getParentASTContext() == &Ctx);
78 if (Ctx.getLangOpts().trackLocalOwningModule()) {
82 llvm::OffsetToAlignment(
sizeof(
Module *),
alignof(
Decl));
83 char *
Buffer =
reinterpret_cast<char *
>(
84 ::operator
new(ExtraAlign +
sizeof(
Module *) + Size + Extra, Ctx));
87 Parent ? cast<Decl>(Parent)->getOwningModule() :
nullptr;
90 return ::operator
new(Size + Extra, Ctx);
93 Module *Decl::getOwningModuleSlow()
const {
104 default: llvm_unreachable(
"Declaration not in DeclNodes.inc!");
105 #define DECL(DERIVED, BASE) case DERIVED: return #DERIVED;
106 #define ABSTRACT_DECL(DECL)
107 #include "clang/AST/DeclNodes.inc"
112 InvalidDecl = Invalid;
113 assert(!isa<TagDecl>(
this) || !cast<TagDecl>(
this)->isCompleteDefinition());
118 if (!isa<ParmVarDecl>(
this)) {
129 Binding->setInvalidDecl();
136 default: llvm_unreachable(
"Declaration context not in DeclNodes.inc!");
137 #define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
138 #define ABSTRACT_DECL(DECL)
139 #include "clang/AST/DeclNodes.inc"
143 bool Decl::StatisticsEnabled =
false;
145 StatisticsEnabled =
true;
149 llvm::errs() <<
"\n*** Decl Stats:\n";
152 #define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s;
153 #define ABSTRACT_DECL(DECL)
154 #include "clang/AST/DeclNodes.inc"
155 llvm::errs() <<
" " << totalDecls <<
" decls total.\n";
158 #define DECL(DERIVED, BASE) \
159 if (n##DERIVED##s > 0) { \
160 totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \
161 llvm::errs() << " " << n##DERIVED##s << " " #DERIVED " decls, " \
162 << sizeof(DERIVED##Decl) << " each (" \
163 << n##DERIVED##s * sizeof(DERIVED##Decl) \
166 #define ABSTRACT_DECL(DECL)
167 #include "clang/AST/DeclNodes.inc"
169 llvm::errs() <<
"Total bytes = " << totalBytes <<
"\n";
174 #define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break;
175 #define ABSTRACT_DECL(DECL)
176 #include "clang/AST/DeclNodes.inc"
182 return TTP->isParameterPack();
184 = dyn_cast<NonTypeTemplateParmDecl>(
this))
185 return NTTP->isParameterPack();
187 = dyn_cast<TemplateTemplateParmDecl>(
this))
188 return TTP->isParameterPack();
193 if (
const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(
this))
194 return Parm->isParameterPack();
203 return FTD->getTemplatedDecl();
208 return isa<TemplateDecl>(
this);
212 if (
auto *FD = dyn_cast<FunctionDecl>(
this))
213 return FD->getDescribedFunctionTemplate();
214 else if (
auto *RD = dyn_cast<CXXRecordDecl>(
this))
215 return RD->getDescribedClassTemplate();
216 else if (
auto *VD = dyn_cast<VarDecl>(
this))
217 return VD->getDescribedVarTemplate();
225 DC = DC->getParent())
226 if (DC->isFunctionOrMethod())
243 TheLoc.
print(OS, SM);
249 if (
const NamedDecl *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) {
251 DN->printQualifiedName(OS);
275 getMultipleDC()->LexicalDC = DC;
289 "hidden declaration has no owning module");
294 if (SemaDC == LexicalDC) {
297 Decl::MultipleDC *MDC =
new (Ctx) Decl::MultipleDC();
298 MDC->SemanticDC = SemaDC;
299 MDC->LexicalDC = LexicalDC;
309 if (!isa<TagDecl>(LDC))
320 if (ND->isAnonymousNamespace())
336 assert(DC &&
"This decl is not contained in a translation unit!");
340 assert(DC &&
"This decl is not contained in a translation unit!");
343 return cast<TranslationUnitDecl>(DC);
363 Align =
std::max(Align,
I->getAlignment(Ctx));
408 if (isa<TranslationUnitDecl>(
this) || isa<NamespaceDecl>(
this))
412 if (cast<Decl>(DC)->isModulePrivate())
414 if (isa<ExportDecl>(DC))
421 const Decl *Definition =
nullptr;
422 if (
auto ID = dyn_cast<ObjCInterfaceDecl>(
this)) {
423 Definition =
ID->getDefinition();
424 }
else if (
auto PD = dyn_cast<ObjCProtocolDecl>(
this)) {
425 Definition = PD->getDefinition();
426 }
else if (
auto TD = dyn_cast<TagDecl>(
this)) {
427 Definition = TD->getDefinition();
432 if (
auto *attr = Definition->
getAttr<ExternalSourceSymbolAttr>())
435 return dcd->
getAttr<ExternalSourceSymbolAttr>();
442 return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>();
446 if (AliasAttr *AA = getAttr<AliasAttr>())
448 if (IFuncAttr *IFA = getAttr<IFuncAttr>())
457 StringRef RealizedPlatform = A->getPlatform()->getName();
459 return RealizedPlatform;
460 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
461 if (suffix != StringRef::npos)
462 return RealizedPlatform.slice(0, suffix);
463 return RealizedPlatform;
476 const AvailabilityAttr *A,
477 std::string *Message,
479 if (EnclosingVersion.
empty())
482 if (EnclosingVersion.
empty())
485 StringRef ActualPlatform = A->getPlatform()->getName();
492 StringRef PrettyPlatformName
493 = AvailabilityAttr::getPrettyPlatformName(ActualPlatform);
495 if (PrettyPlatformName.empty())
496 PrettyPlatformName = ActualPlatform;
498 std::string HintMessage;
499 if (!A->getMessage().empty()) {
501 HintMessage += A->getMessage();
505 if (A->getUnavailable()) {
508 llvm::raw_string_ostream Out(*Message);
509 Out <<
"not available on " << PrettyPlatformName
517 if (!A->getIntroduced().empty() &&
518 EnclosingVersion < A->getIntroduced()) {
521 llvm::raw_string_ostream Out(*Message);
524 Out <<
"introduced in " << PrettyPlatformName <<
' '
525 << VTI << HintMessage;
532 if (!A->getObsoleted().empty() && EnclosingVersion >= A->getObsoleted()) {
535 llvm::raw_string_ostream Out(*Message);
538 Out <<
"obsoleted in " << PrettyPlatformName <<
' '
539 << VTO << HintMessage;
546 if (!A->getDeprecated().empty() && EnclosingVersion >= A->getDeprecated()) {
549 llvm::raw_string_ostream Out(*Message);
552 Out <<
"first deprecated in " << PrettyPlatformName <<
' '
553 << VTD << HintMessage;
564 if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(
this))
565 return FTD->getTemplatedDecl()->getAvailability(Message, EnclosingVersion);
568 std::string ResultMessage;
570 for (
const auto *A :
attrs()) {
571 if (
const auto *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
576 ResultMessage = Deprecated->getMessage();
582 if (
const auto *Unavailable = dyn_cast<UnavailableAttr>(A)) {
584 *Message = Unavailable->getMessage();
588 if (
const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
590 Message, EnclosingVersion);
598 ResultMessage.swap(*Message);
605 Message->swap(ResultMessage);
612 for (
const auto *A :
attrs()) {
613 if (
const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
616 if (!Availability->getIntroduced().empty())
617 return Availability->getIntroduced();
624 IsDefinition =
false;
627 if (
const VarDecl *Var = dyn_cast<VarDecl>(
this)) {
628 if (Var->isThisDeclarationADefinition()) {
635 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(
this)) {
643 }
else if (isa<ObjCInterfaceDecl>(
this) &&
658 for (
const auto *A :
attrs()) {
659 if (isa<WeakImportAttr>(A))
662 if (
const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
675 case CXXDeductionGuide:
678 case ConstructorUsingShadow:
695 case NonTypeTemplateParm:
701 case ObjCCompatibleAlias:
707 case TypeAliasTemplate:
708 case TemplateTypeParm:
712 case UnresolvedUsingTypename:
718 case UnresolvedUsingValue:
729 case ObjCAtDefsField:
742 case FunctionTemplate:
747 case TemplateTemplateParm:
750 case OMPDeclareReduction:
761 case ObjCPropertyImpl:
763 case PragmaDetectMismatch:
766 case TranslationUnit:
771 case BuiltinTemplate:
772 case ClassTemplateSpecialization:
773 case ClassTemplatePartialSpecialization:
774 case ClassScopeFunctionSpecialization:
775 case VarTemplateSpecialization:
776 case VarTemplatePartialSpecialization:
777 case ObjCImplementation:
779 case ObjCCategoryImpl:
781 case OMPThreadPrivate:
782 case OMPCapturedExpr:
788 llvm_unreachable(
"Invalid DeclKind!");
792 assert(!HasAttrs &&
"Decl already contains attrs.");
795 assert(AttrBlank.empty() &&
"HasAttrs was wrong?");
802 if (!HasAttrs)
return;
809 assert(HasAttrs &&
"No attrs to get!");
816 #define DECL(NAME, BASE)
817 #define DECL_CONTEXT(NAME) \
819 return static_cast<NAME##Decl*>(const_cast<DeclContext*>(D));
820 #define DECL_CONTEXT_BASE(NAME)
821 #include "clang/AST/DeclNodes.inc"
823 #define DECL(NAME, BASE)
824 #define DECL_CONTEXT_BASE(NAME) \
825 if (DK >= first##NAME && DK <= last##NAME) \
826 return static_cast<NAME##Decl*>(const_cast<DeclContext*>(D));
827 #include "clang/AST/DeclNodes.inc"
828 llvm_unreachable(
"a decl that inherits DeclContext isn't handled");
835 #define DECL(NAME, BASE)
836 #define DECL_CONTEXT(NAME) \
838 return static_cast<NAME##Decl*>(const_cast<Decl*>(D));
839 #define DECL_CONTEXT_BASE(NAME)
840 #include "clang/AST/DeclNodes.inc"
842 #define DECL(NAME, BASE)
843 #define DECL_CONTEXT_BASE(NAME) \
844 if (DK >= first##NAME && DK <= last##NAME) \
845 return static_cast<NAME##Decl*>(const_cast<Decl*>(D));
846 #include "clang/AST/DeclNodes.inc"
847 llvm_unreachable(
"a decl that inherits DeclContext isn't handled");
854 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(
this)) {
856 if (FD->hasBody(Definition))
862 return Body->getSourceRange().getEnd();
867 bool Decl::AccessDeclContextSanity()
const {
876 if (isa<TranslationUnitDecl>(
this) ||
877 isa<TemplateTypeParmDecl>(
this) ||
878 isa<NonTypeTemplateParmDecl>(
this) ||
881 isa<StaticAssertDecl>(
this) ||
884 isa<ParmVarDecl>(
this) ||
887 isa<CXXRecordDecl>(
this) ||
888 isa<ClassScopeFunctionSpecializationDecl>(
this))
892 "Access specifier is AS_none inside a record decl");
902 if (
const ValueDecl *D = dyn_cast<ValueDecl>(
this))
905 Ty = D->getUnderlyingType();
921 if (
getKind(D) == Decl::CXXMethod) {
927 }
else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
931 }
else if (
BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
933 }
else if (
CapturedDecl *CD = dyn_cast<CapturedDecl>(D)) {
954 #define DECL(NAME, BASE)
955 #define DECL_CONTEXT(NAME) case Decl::NAME:
956 #define DECL_CONTEXT_BASE(NAME)
957 #include "clang/AST/DeclNodes.inc"
960 #define DECL(NAME, BASE)
961 #define DECL_CONTEXT_BASE(NAME) \
962 if (D->getKind() >= Decl::first##NAME && \
963 D->getKind() <= Decl::last##NAME) \
965 #include "clang/AST/DeclNodes.inc"
980 if (isa<FunctionDecl>(
this))
990 cast<NamespaceDecl>(
this)->isInline();
1006 return II && II->
isStr(
"std");
1013 if (isa<ClassTemplatePartialSpecializationDecl>(
this))
1016 if (
const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(
this)) {
1017 if (Record->getDescribedClassTemplate())
1020 if (Record->isDependentLambda())
1024 if (
const FunctionDecl *Function = dyn_cast<FunctionDecl>(
this)) {
1025 if (Function->getDescribedFunctionTemplate())
1030 if (cast<Decl>(
this)->getFriendObjectKind())
1042 if (DeclKind == Decl::Enum)
1043 return !cast<EnumDecl>(
this)->isScoped();
1044 else if (DeclKind == Decl::LinkageSpec || DeclKind == Decl::Export)
1052 while (DC->
getDeclKind() != Decl::TranslationUnit) {
1054 return cast<LinkageSpecDecl>(DC)->getLanguage() ==
ID;
1066 while (DC->
getDeclKind() != Decl::TranslationUnit) {
1068 cast<LinkageSpecDecl>(DC)->getLanguage() ==
1070 return cast<LinkageSpecDecl>(DC);
1092 case Decl::TranslationUnit:
1093 case Decl::ExternCContext:
1094 case Decl::LinkageSpec:
1097 case Decl::Captured:
1098 case Decl::OMPDeclareReduction:
1102 case Decl::Namespace:
1104 return static_cast<NamespaceDecl*
>(
this)->getOriginalNamespace();
1106 case Decl::ObjCMethod:
1109 case Decl::ObjCInterface:
1115 case Decl::ObjCProtocol:
1121 case Decl::ObjCCategory:
1124 case Decl::ObjCImplementation:
1125 case Decl::ObjCCategoryImpl:
1129 if (DeclKind >= Decl::firstTag && DeclKind <= Decl::lastTag) {
1132 TagDecl *Tag = cast<TagDecl>(
this);
1139 TagDecl *PossiblePartialDef = TagTy->getDecl();
1141 return PossiblePartialDef;
1149 assert(DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction &&
1150 "Unknown DeclContext kind");
1159 if (DeclKind != Decl::Namespace) {
1160 Contexts.push_back(
this);
1167 Contexts.push_back(N);
1169 std::reverse(Contexts.begin(), Contexts.end());
1172 std::pair<Decl *, Decl *>
1174 bool FieldsAlreadyLoaded) {
1176 Decl *FirstNewDecl =
nullptr;
1177 Decl *PrevDecl =
nullptr;
1178 for (
unsigned I = 0, N = Decls.size();
I != N; ++
I) {
1179 if (FieldsAlreadyLoaded && isa<FieldDecl>(Decls[
I]))
1191 return std::make_pair(FirstNewDecl, PrevDecl);
1197 void DeclContext::reconcileExternalVisibleStorage()
const {
1198 assert(NeedToReconcileExternalVisibleStorage && LookupPtr);
1199 NeedToReconcileExternalVisibleStorage =
false;
1201 for (
auto &Lookup : *LookupPtr)
1202 Lookup.second.setHasExternalDecls();
1209 DeclContext::LoadLexicalDeclsFromExternalStorage()
const {
1218 ExternalLexicalStorage =
false;
1226 bool FieldsAlreadyLoaded =
false;
1227 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(
this))
1228 FieldsAlreadyLoaded = RD->LoadedFieldsFromExternalStorage;
1232 Decl *ExternalFirst, *ExternalLast;
1233 std::tie(ExternalFirst, ExternalLast) =
1235 ExternalLast->NextInContextAndBits.setPointer(
FirstDecl);
1247 if (!(Map = DC->LookupPtr))
1248 Map = DC->CreateStoredDeclsMap(Context);
1249 if (DC->NeedToReconcileExternalVisibleStorage)
1250 DC->reconcileExternalVisibleStorage();
1252 (*Map)[
Name].removeExternalDecls();
1263 if (!(Map = DC->LookupPtr))
1264 Map = DC->CreateStoredDeclsMap(Context);
1265 if (DC->NeedToReconcileExternalVisibleStorage)
1266 DC->reconcileExternalVisibleStorage();
1279 for (
unsigned I = 0, N = Decls.size();
I != N; ++
I)
1282 Skip.push_back(Decls.size());
1285 unsigned SkipPos = 0;
1286 for (
unsigned I = 0, N = Decls.size(); I != N; ++
I) {
1287 if (I == Skip[SkipPos])
1295 I = Decls.begin(),
E = Decls.end();
I !=
E; ++
I) {
1308 LoadLexicalDeclsFromExternalStorage();
1314 LoadLexicalDeclsFromExternalStorage();
1326 "decl being removed from non-lexical context");
1328 "decl is not in decls list");
1337 for (
Decl *
I =
FirstDecl;
true;
I =
I->NextInContextAndBits.getPointer()) {
1338 assert(
I &&
"decl not found in linked list");
1339 if (
I->NextInContextAndBits.getPointer() == D) {
1351 if (isa<NamedDecl>(D)) {
1361 StoredDeclsMap::iterator Pos = Map->find(ND->
getDeclName());
1362 assert(Pos != Map->end() &&
"no lookup entry for decl");
1363 if (Pos->second.getAsVector() || Pos->second.getAsDecl() == ND)
1364 Pos->second.remove(ND);
1366 }
while (DC->isTransparentContext() && (DC = DC->getParent()));
1372 "Decl inserted into wrong lexical context");
1374 "Decl already inserted into a DeclContext");
1386 Record->addedMember(D);
1391 if (
ImportDecl *Import = dyn_cast<ImportDecl>(D))
1399 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
1400 ND->getDeclContext()->getPrimaryContext()->
1401 makeDeclVisibleInContextWithFlags(ND,
false,
true);
1407 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
1408 ND->getDeclContext()->getPrimaryContext()->
1409 makeDeclVisibleInContextWithFlags(ND,
true,
true);
1429 if (isa<ClassTemplateSpecializationDecl>(D))
1432 if (FD->isFunctionTemplateSpecialization())
1448 if (!HasLazyLocalLexicalLookups && !HasLazyExternalLexicalLookups)
1454 if (HasLazyExternalLexicalLookups) {
1455 HasLazyExternalLexicalLookups =
false;
1456 for (
auto *DC : Contexts) {
1457 if (DC->hasExternalLexicalStorage())
1458 HasLazyLocalLexicalLookups |=
1459 DC->LoadLexicalDeclsFromExternalStorage();
1462 if (!HasLazyLocalLexicalLookups)
1466 for (
auto *DC : Contexts)
1470 HasLazyLocalLexicalLookups =
false;
1478 void DeclContext::buildLookupImpl(
DeclContext *DCtx,
bool Internal) {
1488 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
1490 (!ND->isFromASTFile() ||
1493 makeDeclVisibleInContextImpl(ND, Internal);
1498 if (
DeclContext *InnerCtx = dyn_cast<DeclContext>(D))
1499 if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
1500 buildLookupImpl(InnerCtx, Internal);
1504 NamedDecl *
const DeclContextLookupResult::SingleElementDummyList =
nullptr;
1508 assert(DeclKind != Decl::LinkageSpec && DeclKind != Decl::Export &&
1509 "should not perform lookups into transparent contexts");
1512 if (PrimaryContext !=
this)
1513 return PrimaryContext->
lookup(Name);
1520 (void)cast<Decl>(
this)->getMostRecentDecl();
1523 assert(Source &&
"external visible storage but no external source?");
1525 if (NeedToReconcileExternalVisibleStorage)
1526 reconcileExternalVisibleStorage();
1530 if (HasLazyLocalLexicalLookups || HasLazyExternalLexicalLookups)
1538 std::pair<StoredDeclsMap::iterator, bool> R =
1540 if (!R.second && !R.first->second.hasExternalDecls())
1541 return R.first->second.getLookupResult();
1545 StoredDeclsMap::iterator
I = Map->find(Name);
1546 if (I != Map->end())
1547 return I->second.getLookupResult();
1555 if (HasLazyLocalLexicalLookups || HasLazyExternalLexicalLookups)
1561 StoredDeclsMap::iterator
I = Map->find(Name);
1562 if (I == Map->end())
1565 return I->second.getLookupResult();
1570 assert(DeclKind != Decl::LinkageSpec && DeclKind != Decl::Export &&
1571 "should not perform lookups into transparent contexts");
1574 if (PrimaryContext !=
this)
1580 if (HasLazyLocalLexicalLookups) {
1583 for (
unsigned I = 0, N = Contexts.size();
I != N; ++
I)
1585 HasLazyLocalLexicalLookups =
false;
1592 StoredDeclsMap::iterator
I = Map->find(Name);
1593 return I != Map->end() ? I->second.getLookupResult()
1605 Results.insert(Results.end(), LookupResults.
begin(), LookupResults.
end());
1611 if (Name && !HasLazyLocalLexicalLookups && !HasLazyExternalLexicalLookups) {
1613 StoredDeclsMap::iterator Pos =
Map->find(Name);
1614 if (Pos !=
Map->end()) {
1615 Results.insert(Results.end(),
1616 Pos->second.getLookupResult().begin(),
1617 Pos->second.getLookupResult().end());
1628 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
1629 if (ND->getDeclName() ==
Name)
1630 Results.push_back(ND);
1655 OutermostRD = cast<RecordDecl>(DC);
1684 PrimaryDC->makeDeclVisibleInContextWithFlags(D,
false, PrimaryDC == DeclDC);
1687 void DeclContext::makeDeclVisibleInContextWithFlags(
NamedDecl *D,
bool Internal,
1694 ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
1718 makeDeclVisibleInContextImpl(D, Internal);
1720 HasLazyLocalLexicalLookups =
true;
1727 makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
1729 Decl *DCAsDecl = cast<Decl>(
this);
1731 if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined()))
1733 L->AddedVisibleDecl(
this, D);
1736 void DeclContext::makeDeclVisibleInContextImpl(
NamedDecl *D,
bool Internal) {
1741 Map = CreateStoredDeclsMap(*C);
1767 if (DeclNameEntries.
isNull()) {
1783 return cast<UsingDirectiveDecl>(*I);
1800 assert(!LookupPtr &&
"context already has a decls map");
1802 "creating decls map on non-primary context");
1810 M->Previous = C.LastSDM;
1811 C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
1816 void ASTContext::ReleaseDeclContextMaps() {
1826 llvm::PointerIntPair<StoredDeclsMap*,1>
Next = Map->Previous;
1833 Map = Next.getPointer();
1834 Dependent = Next.getInt();
1842 &&
"cannot iterate dependent diagnostics of non-dependent context");
1844 if (!Parent->LookupPtr)
1845 Parent->CreateStoredDeclsMap(C);
1859 DD->NextDiagnostic = Map->FirstDiagnostic;
1860 Map->FirstDiagnostic = DD;
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...
static StringRef getRealizedPlatform(const AvailabilityAttr *A, const ASTContext &Context)
bool hasOwningModule() const
Is this declaration owned by some module?
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
void setHasExternalDecls()
AttrVec & getDeclAttrs(const Decl *D)
Retrieve the attributes for the given 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.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
void updateOutOfDate(IdentifierInfo &II) const
Update a potentially out-of-date declaration.
static DeclContext * castToDeclContext(const Decl *)
PointerType - C99 6.7.5.1 - Pointer Declarators.
static bool shouldBeHidden(NamedDecl *D)
shouldBeHidden - Determine whether a declaration which was declared within its semantic context shoul...
A (possibly-)qualified type.
UsingDirectiveDecl * operator*() const
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration...
llvm::PointerIntPair< Decl *, 2, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
Represents a version number in the form major[.minor[.subminor[.build]]].
void AddSubsequentDecl(NamedDecl *D)
AddSubsequentDecl - This is called on the second and later decl when it is not a redeclaration to mer...
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.
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple()) const
Determine the availability of the given declaration.
static Decl * castFromDeclContext(const DeclContext *)
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
static bool isLinkageSpecContext(const DeclContext *DC, LinkageSpecDecl::LanguageIDs ID)
Stmt - This represents one statement.
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity, such as 'alias' or 'ifunc'.
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
FunctionType - C99 6.7.5.3 - Function Declarators.
C Language Family Type Representation.
const DeclContext * getParentFunctionOrMethod() const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext...
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.
bool isInStdNamespace() const
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls)
bool isStdNamespace() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
std::unique_ptr< llvm::MemoryBuffer > Buffer
NamespaceDecl - Represent a C++ namespace.
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
bool isBlockPointerType() const
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
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...
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 ...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled...
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
ObjCMethodDecl - Represents an instance or class method declaration.
Decl * FirstDecl
FirstDecl - The first declaration stored within this declaration context.
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
ParmVarDecl - Represents a parameter to a function.
void removeDecl(Decl *D)
Removes a declaration from this context.
Types, declared with 'struct foo', typedefs, etc.
RecordDecl - Represents a struct/union/class.
ASTMutationListener * getASTMutationListener() const
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl, 0 if there are none.
One of these records is kept for each identifier that is lexed.
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 hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
bool isReferenced() const
Whether any declaration of this entity was referenced.
unsigned getIdentifierNamespace() const
bool isTranslationUnit() const
bool isInlineNamespace() const
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl * > Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
Describes a module or submodule.
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)
Update an out-of-date identifier.
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
const TargetInfo & getTargetInfo() const
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...
const LangOptions & getLangOpts() const
Namespaces, declared with 'namespace foo {}'.
bool isInline() const
Returns true if this is an inline namespace declaration.
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
void eraseDeclAttrs(const Decl *D)
Erase the attributes corresponding to the given declaration.
Represents an Objective-C protocol declaration.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
bool hasLocalOwningModuleStorage() const
bool isExported() const
Whether this declaration is exported (by virtue of being lexically within an ExportDecl or by being a...
Labels, declared with 'x:' and referenced with 'goto x'.
void setLocalOwningModule(Module *M)
This represents the body of a CapturedStmt, and serves as its DeclContext.
Represents an ObjC class declaration.
Represents a linkage specification.
decl_iterator decls_begin() const
detail::InMemoryDirectory::const_iterator I
A binding in a decomposition declaration.
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...
AvailabilityResult
Captures the result of checking the availability of a declaration.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
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...
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
bool hasWeakClassImport() const
Does this runtime support weakly importing classes?
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
bool isFunctionPointerType() const
void removeExternalDecls()
Remove any declarations which were imported from an external AST source.
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
const char * getDeclKindName() const
const Type * getTypeForDecl() const
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
QualType getPointeeType() const
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
bool isLookupContext() const
Test whether the context supports looking up names.
static unsigned getIdentifierNamespaceForKind(Kind DK)
llvm::iterator_range< udir_iterator > udir_range
Declaration of a template type parameter.
bool isTemplateDecl() const
returns true if this declaration is a template
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
ASTContext & getParentASTContext() const
const LinkageSpecDecl * getExternCContext() const
Retrieve the nearest enclosing C linkage specification context.
Decl * LastDecl
LastDecl - The last declaration stored within this declaration context.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
This declaration is an OpenMP user defined reduction construction.
bool isInAnonymousNamespace() const
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
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.
const char * getDeclKindName() const
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
friend class DependentDiagnostic
bool isFunctionOrMethod() const
clang::ObjCRuntime ObjCRuntime
This declaration has an owning module, and is visible when that module is imported.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
unsigned Map[FirstTargetAddressSpace]
The type of a lookup table which maps from language-specific address spaces to target-specific ones...
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
TagDecl * getDefinition() const
getDefinition - Returns the TagDecl that actually defines this struct/union/class/enum.
The result type of a method or function.
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
virtual void DeclarationMarkedUsed(const Decl *D)
A declaration is marked used which was not previously marked used.
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
Abstract interface for external sources of AST nodes.
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.
void print(raw_ostream &OS, const SourceManager &SM) const
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Encodes a location in the source.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Members, declared with object declarations within tag definitions.
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
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...
bool isValid() const
Return true if this is a valid SourceLocation object.
TagDecl - Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
Represents a static or instance method of a struct/union/class.
This file defines OpenMP nodes for declarative directives.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
void print(raw_ostream &OS) const override
ASTContext & getASTContext() const
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isFileContext() const
DeclContextLookupResult lookup_result
An array of decls optimized for the common case of only containing one entry.
const Attr * getDefiningAttr() const
Return this declaration's defining attribute if it has one.
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Describes a module import declaration, which makes the contents of the named module visible in the cu...
QualType getPointeeType() const
decl_iterator - Iterates through the declarations stored within this context.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Base class for declarations which introduce a typedef-name.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
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.).
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero)...
bool isInvalidDecl() const
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
A decomposition declaration.
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
DeclarationName - The name of a declaration.
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks, lambdas, etc.
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible. ...
detail::InMemoryDirectory::const_iterator E
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
bool isLambda() const
Determine whether this class describes a lambda function object.
SmallVector< Context, 8 > Contexts
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.
const T * getAs() const
Member-template getAs<specific type>'.
Decl::Kind getDeclKind() const
LanguageIDs
Represents the language in a linkage specification.
Module * getOwningModule() const
Get the module that owns this declaration.
void setOnlyValue(NamedDecl *ND)
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
void addDecl(Decl *D)
Add the declaration D into this context.
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any...
bool isLexicallyWithinFunctionOrMethod() const
Returns true if this declaration lexically is inside a function.
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Represents a C++ struct/union/class.
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
void * Allocate(size_t Size, unsigned Align=8) const
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.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Kind
Lists the kind of concrete classes of Decl.
static Decl::Kind getKind(const Decl *D)
TranslationUnitDecl - 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...
static void EnableStatistics()
bool isParameterPack() const
Whether this declaration is a parameter pack.
SourceLocation getLocation() const
void setLexicalDeclContext(DeclContext *DC)
NamedDecl - This represents a decl with a name.
void setAccess(AccessSpecifier AS)
void collectAllContexts(SmallVectorImpl< DeclContext * > &Contexts)
Collects all of the declaration contexts that are semantically connected to this declaration context...
Represents C++ using-directive.
void addedLocalImportDecl(ImportDecl *Import)
Notify the AST context that a new import declaration has been parsed or implicitly created within thi...
TranslationUnitDecl * getTranslationUnitDecl()
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined...
bool isBeingDefined() const
isBeingDefined - Return true if this decl is currently being defined.
Declaration of a template function.
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. ...
This declaration is a using declaration.
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...