summaryrefslogtreecommitdiffstats
path: root/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r--lib/AST/DeclBase.cpp114
1 files changed, 67 insertions, 47 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 5815d82..96ba19b 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -157,6 +157,25 @@ void Decl::setLexicalDeclContext(DeclContext *DC) {
}
}
+TranslationUnitDecl *Decl::getTranslationUnitDecl() {
+ if (TranslationUnitDecl *TUD = dyn_cast<TranslationUnitDecl>(this))
+ return TUD;
+
+ DeclContext *DC = getDeclContext();
+ assert(DC && "This decl is not contained in a translation unit!");
+
+ while (!DC->isTranslationUnit()) {
+ DC = DC->getParent();
+ assert(DC && "This decl is not contained in a translation unit!");
+ }
+
+ return cast<TranslationUnitDecl>(DC);
+}
+
+ASTContext &Decl::getASTContext() const {
+ return getTranslationUnitDecl()->getASTContext();
+}
+
unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
switch (DeclKind) {
default:
@@ -226,8 +245,8 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
}
}
-void Decl::addAttr(ASTContext &Context, Attr *NewAttr) {
- Attr *&ExistingAttr = Context.getDeclAttrs(this);
+void Decl::addAttr(Attr *NewAttr) {
+ Attr *&ExistingAttr = getASTContext().getDeclAttrs(this);
NewAttr->setNext(ExistingAttr);
ExistingAttr = NewAttr;
@@ -235,19 +254,19 @@ void Decl::addAttr(ASTContext &Context, Attr *NewAttr) {
HasAttrs = true;
}
-void Decl::invalidateAttrs(ASTContext &Context) {
+void Decl::invalidateAttrs() {
if (!HasAttrs) return;
HasAttrs = false;
- Context.eraseDeclAttrs(this);
+ getASTContext().eraseDeclAttrs(this);
}
-const Attr *Decl::getAttrsImpl(ASTContext &Context) const {
+const Attr *Decl::getAttrsImpl() const {
assert(HasAttrs && "getAttrs() should verify this!");
- return Context.getDeclAttrs(this);
+ return getASTContext().getDeclAttrs(this);
}
-void Decl::swapAttrs(ASTContext &Context, Decl *RHS) {
+void Decl::swapAttrs(Decl *RHS) {
bool HasLHSAttr = this->HasAttrs;
bool HasRHSAttr = RHS->HasAttrs;
@@ -256,7 +275,9 @@ void Decl::swapAttrs(ASTContext &Context, Decl *RHS) {
// If 'this' has no attrs, swap the other way.
if (!HasLHSAttr)
- return RHS->swapAttrs(Context, this);
+ return RHS->swapAttrs(this);
+
+ ASTContext &Context = getASTContext();
// Handle the case when both decls have attrs.
if (HasRHSAttr) {
@@ -276,7 +297,7 @@ void Decl::Destroy(ASTContext &C) {
// Free attributes for this decl.
if (HasAttrs) {
C.getDeclAttrs(this)->Destroy(C);
- invalidateAttrs(C);
+ invalidateAttrs();
HasAttrs = false;
}
@@ -339,12 +360,12 @@ DeclContext *Decl::castToDeclContext(const Decl *D) {
}
}
-CompoundStmt* Decl::getCompoundBody(ASTContext &Context) const {
- return dyn_cast_or_null<CompoundStmt>(getBody(Context));
+CompoundStmt* Decl::getCompoundBody() const {
+ return dyn_cast_or_null<CompoundStmt>(getBody());
}
-SourceLocation Decl::getBodyRBrace(ASTContext &Context) const {
- Stmt *Body = getBody(Context);
+SourceLocation Decl::getBodyRBrace() const {
+ Stmt *Body = getBody();
if (!Body)
return SourceLocation();
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Body))
@@ -388,7 +409,7 @@ DeclContext::~DeclContext() {
}
void DeclContext::DestroyDecls(ASTContext &C) {
- for (decl_iterator D = decls_begin(C); D != decls_end(C); )
+ for (decl_iterator D = decls_begin(); D != decls_end(); )
(*D++)->Destroy(C);
}
@@ -479,8 +500,8 @@ DeclContext *DeclContext::getNextContext() {
/// \brief Load the declarations within this lexical storage from an
/// external source.
void
-DeclContext::LoadLexicalDeclsFromExternalStorage(ASTContext &Context) const {
- ExternalASTSource *Source = Context.getExternalSource();
+DeclContext::LoadLexicalDeclsFromExternalStorage() const {
+ ExternalASTSource *Source = getParentASTContext().getExternalSource();
assert(hasExternalLexicalStorage() && Source && "No external storage?");
llvm::SmallVector<uint32_t, 64> Decls;
@@ -517,9 +538,9 @@ DeclContext::LoadLexicalDeclsFromExternalStorage(ASTContext &Context) const {
}
void
-DeclContext::LoadVisibleDeclsFromExternalStorage(ASTContext &Context) const {
+DeclContext::LoadVisibleDeclsFromExternalStorage() const {
DeclContext *This = const_cast<DeclContext *>(this);
- ExternalASTSource *Source = Context.getExternalSource();
+ ExternalASTSource *Source = getParentASTContext().getExternalSource();
assert(hasExternalVisibleStorage() && Source && "No external storage?");
llvm::SmallVector<VisibleDeclaration, 64> Decls;
@@ -539,30 +560,30 @@ DeclContext::LoadVisibleDeclsFromExternalStorage(ASTContext &Context) const {
}
}
-DeclContext::decl_iterator DeclContext::decls_begin(ASTContext &Context) const {
+DeclContext::decl_iterator DeclContext::decls_begin() const {
if (hasExternalLexicalStorage())
- LoadLexicalDeclsFromExternalStorage(Context);
+ LoadLexicalDeclsFromExternalStorage();
// FIXME: Check whether we need to load some declarations from
// external storage.
return decl_iterator(FirstDecl);
}
-DeclContext::decl_iterator DeclContext::decls_end(ASTContext &Context) const {
+DeclContext::decl_iterator DeclContext::decls_end() const {
if (hasExternalLexicalStorage())
- LoadLexicalDeclsFromExternalStorage(Context);
+ LoadLexicalDeclsFromExternalStorage();
return decl_iterator();
}
-bool DeclContext::decls_empty(ASTContext &Context) const {
+bool DeclContext::decls_empty() const {
if (hasExternalLexicalStorage())
- LoadLexicalDeclsFromExternalStorage(Context);
+ LoadLexicalDeclsFromExternalStorage();
return !FirstDecl;
}
-void DeclContext::addDecl(ASTContext &Context, Decl *D) {
+void DeclContext::addDecl(Decl *D) {
assert(D->getLexicalDeclContext() == this &&
"Decl inserted into wrong lexical context");
assert(!D->getNextDeclInContext() && D != LastDecl &&
@@ -576,44 +597,44 @@ void DeclContext::addDecl(ASTContext &Context, Decl *D) {
}
if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
- ND->getDeclContext()->makeDeclVisibleInContext(Context, ND);
+ ND->getDeclContext()->makeDeclVisibleInContext(ND);
}
/// buildLookup - Build the lookup data structure with all of the
/// declarations in DCtx (and any other contexts linked to it or
/// transparent contexts nested within it).
-void DeclContext::buildLookup(ASTContext &Context, DeclContext *DCtx) {
+void DeclContext::buildLookup(DeclContext *DCtx) {
for (; DCtx; DCtx = DCtx->getNextContext()) {
- for (decl_iterator D = DCtx->decls_begin(Context),
- DEnd = DCtx->decls_end(Context);
+ for (decl_iterator D = DCtx->decls_begin(),
+ DEnd = DCtx->decls_end();
D != DEnd; ++D) {
// Insert this declaration into the lookup structure
if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
- makeDeclVisibleInContextImpl(Context, ND);
+ makeDeclVisibleInContextImpl(ND);
// If this declaration is itself a transparent declaration context,
// add its members (recursively).
if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D))
if (InnerCtx->isTransparentContext())
- buildLookup(Context, InnerCtx->getPrimaryContext());
+ buildLookup(InnerCtx->getPrimaryContext());
}
}
}
DeclContext::lookup_result
-DeclContext::lookup(ASTContext &Context, DeclarationName Name) {
+DeclContext::lookup(DeclarationName Name) {
DeclContext *PrimaryContext = getPrimaryContext();
if (PrimaryContext != this)
- return PrimaryContext->lookup(Context, Name);
+ return PrimaryContext->lookup(Name);
if (hasExternalVisibleStorage())
- LoadVisibleDeclsFromExternalStorage(Context);
+ LoadVisibleDeclsFromExternalStorage();
/// If there is no lookup data structure, build one now by walking
/// all of the linked DeclContexts (in declaration order!) and
/// inserting their values.
if (!LookupPtr) {
- buildLookup(Context, this);
+ buildLookup(this);
if (!LookupPtr)
return lookup_result(0, 0);
@@ -623,12 +644,12 @@ DeclContext::lookup(ASTContext &Context, DeclarationName Name) {
StoredDeclsMap::iterator Pos = Map->find(Name);
if (Pos == Map->end())
return lookup_result(0, 0);
- return Pos->second.getLookupResult(Context);
+ return Pos->second.getLookupResult(getParentASTContext());
}
DeclContext::lookup_const_result
-DeclContext::lookup(ASTContext &Context, DeclarationName Name) const {
- return const_cast<DeclContext*>(this)->lookup(Context, Name);
+DeclContext::lookup(DeclarationName Name) const {
+ return const_cast<DeclContext*>(this)->lookup(Name);
}
DeclContext *DeclContext::getLookupContext() {
@@ -647,7 +668,7 @@ DeclContext *DeclContext::getEnclosingNamespaceContext() {
return Ctx->getPrimaryContext();
}
-void DeclContext::makeDeclVisibleInContext(ASTContext &Context, NamedDecl *D) {
+void DeclContext::makeDeclVisibleInContext(NamedDecl *D) {
// FIXME: This feels like a hack. Should DeclarationName support
// template-ids, or is there a better way to keep specializations
// from being visible?
@@ -656,7 +677,7 @@ void DeclContext::makeDeclVisibleInContext(ASTContext &Context, NamedDecl *D) {
DeclContext *PrimaryContext = getPrimaryContext();
if (PrimaryContext != this) {
- PrimaryContext->makeDeclVisibleInContext(Context, D);
+ PrimaryContext->makeDeclVisibleInContext(D);
return;
}
@@ -664,16 +685,15 @@ void DeclContext::makeDeclVisibleInContext(ASTContext &Context, NamedDecl *D) {
// into it. Otherwise, be lazy and don't build that structure until
// someone asks for it.
if (LookupPtr)
- makeDeclVisibleInContextImpl(Context, D);
+ makeDeclVisibleInContextImpl(D);
// If we are a transparent context, insert into our parent context,
// too. This operation is recursive.
if (isTransparentContext())
- getParent()->makeDeclVisibleInContext(Context, D);
+ getParent()->makeDeclVisibleInContext(D);
}
-void DeclContext::makeDeclVisibleInContextImpl(ASTContext &Context,
- NamedDecl *D) {
+void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) {
// Skip unnamed declarations.
if (!D->getDeclName())
return;
@@ -698,7 +718,7 @@ void DeclContext::makeDeclVisibleInContextImpl(ASTContext &Context,
// If it is possible that this is a redeclaration, check to see if there is
// already a decl for which declarationReplaces returns true. If there is
// one, just replace it and return.
- if (DeclNameEntries.HandleRedeclaration(Context, D))
+ if (DeclNameEntries.HandleRedeclaration(getParentASTContext(), D))
return;
// Put this declaration into the appropriate slot.
@@ -708,8 +728,8 @@ void DeclContext::makeDeclVisibleInContextImpl(ASTContext &Context,
/// Returns iterator range [First, Last) of UsingDirectiveDecls stored within
/// this context.
DeclContext::udir_iterator_range
-DeclContext::getUsingDirectives(ASTContext &Context) const {
- lookup_const_result Result = lookup(Context, UsingDirectiveDecl::getName());
+DeclContext::getUsingDirectives() const {
+ lookup_const_result Result = lookup(UsingDirectiveDecl::getName());
return udir_iterator_range(reinterpret_cast<udir_iterator>(Result.first),
reinterpret_cast<udir_iterator>(Result.second));
}
OpenPOWER on IntegriCloud