31 #include "llvm/ADT/DenseMap.h"
32 #include "llvm/Support/raw_ostream.h"
34 using namespace clang;
40 #define DECL(DERIVED, BASE) static int n##DERIVED##s = 0;
41 #define ABSTRACT_DECL(DECL)
42 #include "clang/AST/DeclNodes.inc"
48 #define DECL(DERIVED, BASE) \
49 static_assert(Decl::DeclObjAlignment >= \
50 llvm::AlignOf<DERIVED##Decl>::Alignment, \
51 "Alignment sufficient after objects prepended to " #DERIVED);
52 #define ABSTRACT_DECL(DECL)
53 #include "clang/AST/DeclNodes.inc"
59 static_assert(
sizeof(
unsigned) * 2 >= DeclObjAlignment,
60 "Decl won't be misaligned");
62 void *
Result = (
char*)Start + 8;
64 unsigned *PrefixPtr = (
unsigned *)Result - 2;
77 assert(!Parent || &Parent->getParentASTContext() == &Ctx);
80 if (Ctx.getLangOpts().ModulesLocalVisibility) {
84 llvm::OffsetToAlignment(
sizeof(
Module *), DeclObjAlignment);
85 char *
Buffer =
reinterpret_cast<char *
>(
86 ::operator
new(ExtraAlign +
sizeof(
Module *) + Size + Extra, Ctx));
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());
114 if (Invalid && !isa<ParmVarDecl>(
this)) {
124 default: llvm_unreachable(
"Declaration context not in DeclNodes.inc!");
125 #define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
126 #define ABSTRACT_DECL(DECL)
127 #include "clang/AST/DeclNodes.inc"
131 bool Decl::StatisticsEnabled =
false;
133 StatisticsEnabled =
true;
137 llvm::errs() <<
"\n*** Decl Stats:\n";
140 #define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s;
141 #define ABSTRACT_DECL(DECL)
142 #include "clang/AST/DeclNodes.inc"
143 llvm::errs() <<
" " << totalDecls <<
" decls total.\n";
146 #define DECL(DERIVED, BASE) \
147 if (n##DERIVED##s > 0) { \
148 totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \
149 llvm::errs() << " " << n##DERIVED##s << " " #DERIVED " decls, " \
150 << sizeof(DERIVED##Decl) << " each (" \
151 << n##DERIVED##s * sizeof(DERIVED##Decl) \
154 #define ABSTRACT_DECL(DECL)
155 #include "clang/AST/DeclNodes.inc"
157 llvm::errs() <<
"Total bytes = " << totalBytes <<
"\n";
162 #define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break;
163 #define ABSTRACT_DECL(DECL)
164 #include "clang/AST/DeclNodes.inc"
170 return TTP->isParameterPack();
172 = dyn_cast<NonTypeTemplateParmDecl>(
this))
173 return NTTP->isParameterPack();
175 = dyn_cast<TemplateTemplateParmDecl>(
this))
176 return TTP->isParameterPack();
181 if (
const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(
this))
182 return Parm->isParameterPack();
191 return FTD->getTemplatedDecl();
196 return isa<TemplateDecl>(
this);
202 DC = DC->getParent())
203 if (DC->isFunctionOrMethod())
220 TheLoc.
print(OS, SM);
226 if (
const NamedDecl *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) {
228 DN->printQualifiedName(OS);
252 getMultipleDC()->LexicalDC = DC;
259 if (SemaDC == LexicalDC) {
262 Decl::MultipleDC *MDC =
new (Ctx) Decl::MultipleDC();
263 MDC->SemanticDC = SemaDC;
264 MDC->LexicalDC = LexicalDC;
274 if (!isa<TagDecl>(LDC))
285 if (ND->isAnonymousNamespace())
301 assert(DC &&
"This decl is not contained in a translation unit!");
305 assert(DC &&
"This decl is not contained in a translation unit!");
308 return cast<TranslationUnitDecl>(DC);
328 Align = std::max(Align,
I->getAlignment(Ctx));
337 if (CheckUsedAttr && hasAttr<UsedAttr>())
375 const AvailabilityAttr *A,
376 std::string *Message) {
380 if (TargetMinVersion.
empty())
385 StringRef ActualPlatform = A->getPlatform()->getName();
386 StringRef RealizedPlatform = ActualPlatform;
388 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
389 if (suffix != StringRef::npos)
390 RealizedPlatform = RealizedPlatform.slice(0, suffix);
396 if (RealizedPlatform != TargetPlatform)
399 StringRef PrettyPlatformName
400 = AvailabilityAttr::getPrettyPlatformName(ActualPlatform);
402 if (PrettyPlatformName.empty())
403 PrettyPlatformName = ActualPlatform;
405 std::string HintMessage;
406 if (!A->getMessage().empty()) {
408 HintMessage += A->getMessage();
412 if (A->getUnavailable()) {
415 llvm::raw_string_ostream Out(*Message);
416 Out <<
"not available on " << PrettyPlatformName
424 if (!A->getIntroduced().empty() &&
425 TargetMinVersion < A->getIntroduced()) {
428 llvm::raw_string_ostream Out(*Message);
431 Out <<
"introduced in " << PrettyPlatformName <<
' '
432 << VTI << HintMessage;
439 if (!A->getObsoleted().empty() && TargetMinVersion >= A->getObsoleted()) {
442 llvm::raw_string_ostream Out(*Message);
445 Out <<
"obsoleted in " << PrettyPlatformName <<
' '
446 << VTO << HintMessage;
453 if (!A->getDeprecated().empty() && TargetMinVersion >= A->getDeprecated()) {
456 llvm::raw_string_ostream Out(*Message);
459 Out <<
"first deprecated in " << PrettyPlatformName <<
' '
460 << VTD << HintMessage;
471 std::string ResultMessage;
473 for (
const auto *A :
attrs()) {
474 if (
const auto *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
479 ResultMessage = Deprecated->getMessage();
485 if (
const auto *Unavailable = dyn_cast<UnavailableAttr>(A)) {
487 *Message = Unavailable->getMessage();
491 if (
const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
501 ResultMessage.swap(*Message);
508 Message->swap(ResultMessage);
513 IsDefinition =
false;
516 if (
const VarDecl *Var = dyn_cast<VarDecl>(
this)) {
517 if (Var->isThisDeclarationADefinition()) {
524 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(
this)) {
532 }
else if (isa<ObjCInterfaceDecl>(
this) &&
547 for (
const auto *A :
attrs()) {
548 if (isa<WeakImportAttr>(A))
551 if (
const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
581 case NonTypeTemplateParm:
587 case ObjCCompatibleAlias:
593 case TypeAliasTemplate:
594 case UnresolvedUsingTypename:
595 case TemplateTypeParm:
602 case UnresolvedUsingValue:
612 case ObjCAtDefsField:
625 case FunctionTemplate:
630 case TemplateTemplateParm:
640 case ObjCPropertyImpl:
643 case TranslationUnit:
647 case BuiltinTemplate:
648 case ClassTemplateSpecialization:
649 case ClassTemplatePartialSpecialization:
650 case ClassScopeFunctionSpecialization:
651 case VarTemplateSpecialization:
652 case VarTemplatePartialSpecialization:
653 case ObjCImplementation:
655 case ObjCCategoryImpl:
657 case OMPThreadPrivate:
663 llvm_unreachable(
"Invalid DeclKind!");
667 assert(!HasAttrs &&
"Decl already contains attrs.");
670 assert(AttrBlank.empty() &&
"HasAttrs was wrong?");
677 if (!HasAttrs)
return;
684 assert(HasAttrs &&
"No attrs to get!");
691 #define DECL(NAME, BASE)
692 #define DECL_CONTEXT(NAME) \
694 return static_cast<NAME##Decl*>(const_cast<DeclContext*>(D));
695 #define DECL_CONTEXT_BASE(NAME)
696 #include "clang/AST/DeclNodes.inc"
698 #define DECL(NAME, BASE)
699 #define DECL_CONTEXT_BASE(NAME) \
700 if (DK >= first##NAME && DK <= last##NAME) \
701 return static_cast<NAME##Decl*>(const_cast<DeclContext*>(D));
702 #include "clang/AST/DeclNodes.inc"
703 llvm_unreachable(
"a decl that inherits DeclContext isn't handled");
710 #define DECL(NAME, BASE)
711 #define DECL_CONTEXT(NAME) \
713 return static_cast<NAME##Decl*>(const_cast<Decl*>(D));
714 #define DECL_CONTEXT_BASE(NAME)
715 #include "clang/AST/DeclNodes.inc"
717 #define DECL(NAME, BASE)
718 #define DECL_CONTEXT_BASE(NAME) \
719 if (DK >= first##NAME && DK <= last##NAME) \
720 return static_cast<NAME##Decl*>(const_cast<Decl*>(D));
721 #include "clang/AST/DeclNodes.inc"
722 llvm_unreachable(
"a decl that inherits DeclContext isn't handled");
729 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(
this)) {
731 if (FD->hasBody(Definition))
737 return Body->getSourceRange().getEnd();
742 bool Decl::AccessDeclContextSanity()
const {
751 if (isa<TranslationUnitDecl>(
this) ||
752 isa<TemplateTypeParmDecl>(
this) ||
753 isa<NonTypeTemplateParmDecl>(
this) ||
756 isa<StaticAssertDecl>(
this) ||
759 isa<ParmVarDecl>(
this) ||
762 isa<CXXRecordDecl>(
this) ||
763 isa<ClassScopeFunctionSpecializationDecl>(
this))
767 "Access specifier is AS_none inside a record decl");
777 if (
const ValueDecl *D = dyn_cast<ValueDecl>(
this))
780 Ty = D->getUnderlyingType();
796 if (
getKind(D) == Decl::CXXMethod) {
802 }
else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
806 }
else if (
BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
808 }
else if (
CapturedDecl *CD = dyn_cast<CapturedDecl>(D)) {
829 #define DECL(NAME, BASE)
830 #define DECL_CONTEXT(NAME) case Decl::NAME:
831 #define DECL_CONTEXT_BASE(NAME)
832 #include "clang/AST/DeclNodes.inc"
835 #define DECL(NAME, BASE)
836 #define DECL_CONTEXT_BASE(NAME) \
837 if (D->getKind() >= Decl::first##NAME && \
838 D->getKind() <= Decl::last##NAME) \
840 #include "clang/AST/DeclNodes.inc"
855 if (isa<FunctionDecl>(
this))
865 cast<NamespaceDecl>(
this)->isInline();
881 return II && II->
isStr(
"std");
888 if (isa<ClassTemplatePartialSpecializationDecl>(
this))
891 if (
const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(
this)) {
892 if (Record->getDescribedClassTemplate())
895 if (Record->isDependentLambda())
899 if (
const FunctionDecl *Function = dyn_cast<FunctionDecl>(
this)) {
900 if (Function->getDescribedFunctionTemplate())
905 if (cast<Decl>(
this)->getFriendObjectKind())
917 if (DeclKind == Decl::Enum)
918 return !cast<EnumDecl>(
this)->isScoped();
919 else if (DeclKind == Decl::LinkageSpec)
927 while (DC->
getDeclKind() != Decl::TranslationUnit) {
929 return cast<LinkageSpecDecl>(DC)->getLanguage() ==
ID;
955 case Decl::TranslationUnit:
956 case Decl::ExternCContext:
957 case Decl::LinkageSpec:
963 case Decl::Namespace:
965 return static_cast<NamespaceDecl*
>(
this)->getOriginalNamespace();
967 case Decl::ObjCMethod:
970 case Decl::ObjCInterface:
976 case Decl::ObjCProtocol:
982 case Decl::ObjCCategory:
985 case Decl::ObjCImplementation:
986 case Decl::ObjCCategoryImpl:
990 if (DeclKind >= Decl::firstTag && DeclKind <= Decl::lastTag) {
993 TagDecl *Tag = cast<TagDecl>(
this);
1000 TagDecl *PossiblePartialDef = TagTy->getDecl();
1002 return PossiblePartialDef;
1010 assert(DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction &&
1011 "Unknown DeclContext kind");
1020 if (DeclKind != Decl::Namespace) {
1021 Contexts.push_back(
this);
1028 Contexts.push_back(N);
1030 std::reverse(Contexts.begin(), Contexts.end());
1033 std::pair<Decl *, Decl *>
1035 bool FieldsAlreadyLoaded) {
1037 Decl *FirstNewDecl =
nullptr;
1038 Decl *PrevDecl =
nullptr;
1039 for (
unsigned I = 0, N = Decls.size();
I != N; ++
I) {
1040 if (FieldsAlreadyLoaded && isa<FieldDecl>(Decls[
I]))
1052 return std::make_pair(FirstNewDecl, PrevDecl);
1058 void DeclContext::reconcileExternalVisibleStorage()
const {
1059 assert(NeedToReconcileExternalVisibleStorage && LookupPtr);
1060 NeedToReconcileExternalVisibleStorage =
false;
1062 for (
auto &Lookup : *LookupPtr)
1063 Lookup.second.setHasExternalDecls();
1070 DeclContext::LoadLexicalDeclsFromExternalStorage()
const {
1079 ExternalLexicalStorage =
false;
1087 bool FieldsAlreadyLoaded =
false;
1088 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(
this))
1089 FieldsAlreadyLoaded = RD->LoadedFieldsFromExternalStorage;
1093 Decl *ExternalFirst, *ExternalLast;
1094 std::tie(ExternalFirst, ExternalLast) =
1096 ExternalLast->NextInContextAndBits.setPointer(
FirstDecl);
1108 if (!(Map = DC->LookupPtr))
1109 Map = DC->CreateStoredDeclsMap(Context);
1110 if (DC->NeedToReconcileExternalVisibleStorage)
1111 DC->reconcileExternalVisibleStorage();
1113 (*Map)[
Name].removeExternalDecls();
1124 if (!(Map = DC->LookupPtr))
1125 Map = DC->CreateStoredDeclsMap(Context);
1126 if (DC->NeedToReconcileExternalVisibleStorage)
1127 DC->reconcileExternalVisibleStorage();
1140 for (
unsigned I = 0, N = Decls.size();
I != N; ++
I)
1143 Skip.push_back(Decls.size());
1146 unsigned SkipPos = 0;
1147 for (
unsigned I = 0, N = Decls.size(); I != N; ++
I) {
1148 if (I == Skip[SkipPos])
1156 I = Decls.begin(),
E = Decls.end();
I !=
E; ++
I) {
1169 LoadLexicalDeclsFromExternalStorage();
1175 LoadLexicalDeclsFromExternalStorage();
1187 "decl being removed from non-lexical context");
1189 "decl is not in decls list");
1198 for (
Decl *
I =
FirstDecl;
true;
I =
I->NextInContextAndBits.getPointer()) {
1199 assert(
I &&
"decl not found in linked list");
1200 if (
I->NextInContextAndBits.getPointer() == D) {
1212 if (isa<NamedDecl>(D)) {
1223 assert(Pos != Map->end() &&
"no lookup entry for decl");
1224 if (Pos->second.getAsVector() || Pos->second.getAsDecl() == ND)
1225 Pos->second.remove(ND);
1227 }
while (DC->isTransparentContext() && (DC = DC->getParent()));
1233 "Decl inserted into wrong lexical context");
1235 "Decl already inserted into a DeclContext");
1247 Record->addedMember(D);
1252 if (
ImportDecl *Import = dyn_cast<ImportDecl>(D))
1260 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
1261 ND->getDeclContext()->getPrimaryContext()->
1262 makeDeclVisibleInContextWithFlags(ND,
false,
true);
1268 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
1269 ND->getDeclContext()->getPrimaryContext()->
1270 makeDeclVisibleInContextWithFlags(ND,
true,
true);
1290 if (isa<ClassTemplateSpecializationDecl>(D))
1293 if (FD->isFunctionTemplateSpecialization())
1309 if (!HasLazyLocalLexicalLookups && !HasLazyExternalLexicalLookups)
1315 if (HasLazyExternalLexicalLookups) {
1316 HasLazyExternalLexicalLookups =
false;
1317 for (
auto *DC : Contexts) {
1318 if (DC->hasExternalLexicalStorage())
1319 HasLazyLocalLexicalLookups |=
1320 DC->LoadLexicalDeclsFromExternalStorage();
1323 if (!HasLazyLocalLexicalLookups)
1327 for (
auto *DC : Contexts)
1331 HasLazyLocalLexicalLookups =
false;
1339 void DeclContext::buildLookupImpl(
DeclContext *DCtx,
bool Internal) {
1349 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
1351 (!ND->isFromASTFile() ||
1354 makeDeclVisibleInContextImpl(ND, Internal);
1359 if (
DeclContext *InnerCtx = dyn_cast<DeclContext>(D))
1360 if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
1361 buildLookupImpl(InnerCtx, Internal);
1365 NamedDecl *
const DeclContextLookupResult::SingleElementDummyList =
nullptr;
1369 assert(DeclKind != Decl::LinkageSpec &&
1370 "Should not perform lookups into linkage specs!");
1373 if (PrimaryContext !=
this)
1374 return PrimaryContext->
lookup(Name);
1381 (void)cast<Decl>(
this)->getMostRecentDecl();
1384 assert(Source &&
"external visible storage but no external source?");
1386 if (NeedToReconcileExternalVisibleStorage)
1387 reconcileExternalVisibleStorage();
1391 if (HasLazyLocalLexicalLookups || HasLazyExternalLexicalLookups)
1399 std::pair<StoredDeclsMap::iterator, bool> R =
1401 if (!R.second && !R.first->second.hasExternalDecls())
1402 return R.first->second.getLookupResult();
1407 if (I != Map->end())
1408 return I->second.getLookupResult();
1416 if (HasLazyLocalLexicalLookups || HasLazyExternalLexicalLookups)
1423 if (I == Map->end())
1426 return I->second.getLookupResult();
1431 assert(DeclKind != Decl::LinkageSpec &&
1432 "Should not perform lookups into linkage specs!");
1435 if (PrimaryContext !=
this)
1441 if (HasLazyLocalLexicalLookups) {
1444 for (
unsigned I = 0, N = Contexts.size();
I != N; ++
I)
1446 HasLazyLocalLexicalLookups =
false;
1454 return I != Map->end() ? I->second.getLookupResult()
1466 Results.insert(Results.end(), LookupResults.
begin(), LookupResults.
end());
1472 if (Name && !HasLazyLocalLexicalLookups && !HasLazyExternalLexicalLookups) {
1475 if (Pos !=
Map->end()) {
1476 Results.insert(Results.end(),
1477 Pos->second.getLookupResult().begin(),
1478 Pos->second.getLookupResult().end());
1489 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
1490 if (ND->getDeclName() ==
Name)
1491 Results.push_back(ND);
1516 OutermostRD = cast<RecordDecl>(DC);
1545 PrimaryDC->makeDeclVisibleInContextWithFlags(D,
false, PrimaryDC == DeclDC);
1548 void DeclContext::makeDeclVisibleInContextWithFlags(
NamedDecl *D,
bool Internal,
1576 makeDeclVisibleInContextImpl(D, Internal);
1578 HasLazyLocalLexicalLookups =
true;
1585 makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
1587 Decl *DCAsDecl = cast<Decl>(
this);
1589 if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined()))
1591 L->AddedVisibleDecl(
this, D);
1594 void DeclContext::makeDeclVisibleInContextImpl(
NamedDecl *D,
bool Internal) {
1599 Map = CreateStoredDeclsMap(*C);
1625 if (DeclNameEntries.
isNull()) {
1641 return cast<UsingDirectiveDecl>(*I);
1658 assert(!LookupPtr &&
"context already has a decls map");
1660 "creating decls map on non-primary context");
1668 M->Previous = C.LastSDM;
1669 C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
1674 void ASTContext::ReleaseDeclContextMaps() {
1684 llvm::PointerIntPair<StoredDeclsMap*,1>
Next = Map->Previous;
1691 Map = Next.getPointer();
1692 Dependent = Next.getInt();
1700 &&
"cannot iterate dependent diagnostics of non-dependent context");
1702 if (!Parent->LookupPtr)
1703 Parent->CreateStoredDeclsMap(C);
1717 DD->NextDiagnostic = Map->FirstDiagnostic;
1718 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...
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
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.
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)
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...
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.
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.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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
Labels, declared with 'x:' and referenced with 'goto x'.
This represents the body of a CapturedStmt, and serves as its DeclContext.
Represents an ObjC class declaration.
decl_iterator decls_begin() const
detail::InMemoryDirectory::const_iterator I
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...
AvailabilityResult getAvailability(std::string *Message=nullptr) const
Determine the availability of the given declaration.
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.
ID
Defines the set of possible language-specific address spaces.
bool isFunctionPointerType() const
void removeExternalDecls()
Remove any declarations which were imported from an external AST source.
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...
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
Decl * LastDecl
LastDecl - The last declaration stored within this declaration context.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isInAnonymousNamespace() 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.
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
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...
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.
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.
const TemplateArgument * iterator
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.
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...
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) ...
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
DeclarationName - The name of a declaration.
bool isUsed(bool CheckUsedAttr=true) const
Whether this declaration 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'.
static AvailabilityResult CheckAvailability(ASTContext &Context, const AvailabilityAttr *A, std::string *Message)
Determine the availability of the given declaration based on the target platform. ...
bool isLambda() const
Determine whether this class describes a lambda function object.
unsigned Map[Count]
The type of a lookup table which maps from language-specific address spaces to target-specific ones...
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)
bool TypeAlias
Whether this template specialization type is a substituted type alias.
const T * getAs() const
Member-template getAs<specific type>'.
Decl::Kind getDeclKind() const
LanguageIDs
Represents the language in a linkage specification.
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.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
unsigned Hidden
Whether this declaration is hidden from normal name lookup, e.g., because it is was loaded from an AS...
llvm::PointerIntPair< Decl *, 2, unsigned > NextInContextAndBits
The next declaration within the same lexical DeclContext.
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 isBeingDefined() const
isBeingDefined - Return true if this decl is currently being defined.
Declaration of a template function.
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...