summaryrefslogtreecommitdiffstats
path: root/clang/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-26 06:24:45 +0000
committerChris Lattner <sabre@nondot.org>2007-08-26 06:24:45 +0000
commit1a76a3c970ff358f1f252173b0ee6e578181f24f (patch)
treedc7c076085a47c637a8cdb07bb15b5788691284d /clang/Sema/SemaDecl.cpp
parent88078594fc05e0bbfb67fb7c19a45761739c3c94 (diff)
downloadbcm5719-llvm-1a76a3c970ff358f1f252173b0ee6e578181f24f.tar.gz
bcm5719-llvm-1a76a3c970ff358f1f252173b0ee6e578181f24f.zip
Break the assumption that any sort of scope (e.g. a loop scope) can
hold declarations. Instead, introduce a new "DeclScope" scope type that holds them explicitly. For now, all scopes have this bit, but in the future we can use them to fix some issues Neil noticed. llvm-svn: 41431
Diffstat (limited to 'clang/Sema/SemaDecl.cpp')
-rw-r--r--clang/Sema/SemaDecl.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index faf016b9448..543d2af4544 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -78,6 +78,9 @@ Sema::DeclTy *Sema::isTypeName(const IdentifierInfo &II, Scope *S) const {
}
void Sema::PopScope(SourceLocation Loc, Scope *S) {
+ if (S->decl_empty()) return;
+ assert((S->getFlags() & Scope::DeclScope) &&"Scope shouldn't contain decls!");
+
for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
I != E; ++I) {
Decl *D = static_cast<Decl*>(*I);
@@ -159,6 +162,8 @@ Decl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid, Scope *S) {
FunctionDecl::Extern, false, 0);
// Find translation-unit scope to insert this function into.
+ if (Scope *FnS = S->getFnParent())
+ S = FnS->getParent(); // Skip all scopes in a function at once.
while (S->getParent())
S = S->getParent();
S->AddDecl(New);
@@ -286,6 +291,11 @@ Sema::ParseDeclarator(Scope *S, Declarator &D, ExprTy *init,
return 0;
}
+ // The scope passed in may not be a decl scope. Zip up the scope tree until
+ // we find one that is.
+ while ((S->getFlags() & Scope::DeclScope) == 0)
+ S = S->getParent();
+
// See if this is a redefinition of a variable in the same scope.
Decl *PrevDecl = LookupScopedDecl(II, Decl::IDNS_Ordinary,
D.getIdentifierLoc(), S);
@@ -616,6 +626,8 @@ Decl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
D.SetIdentifier(&II, Loc);
// Find translation-unit scope to insert this function into.
+ if (Scope *FnS = S->getFnParent())
+ S = FnS->getParent(); // Skip all scopes in a function at once.
while (S->getParent())
S = S->getParent();
@@ -724,6 +736,12 @@ Sema::DeclTy *Sema::ParseTag(Scope *S, unsigned TagType, TagKind TK,
// If this has an identifier, add it to the scope stack.
if (Name) {
+ // The scope passed in may not be a decl scope. Zip up the scope tree until
+ // we find one that is.
+ while ((S->getFlags() & Scope::DeclScope) == 0)
+ S = S->getParent();
+
+ // Add it to the decl chain.
New->setNext(Name->getFETokenInfo<Decl>());
Name->setFETokenInfo(New);
S->AddDecl(New);
@@ -896,6 +914,11 @@ Sema::DeclTy *Sema::ParseEnumConstant(Scope *S, DeclTy *theEnumDecl,
cast_or_null<EnumConstantDecl>(static_cast<Decl*>(lastEnumConst));
Expr *Val = static_cast<Expr*>(val);
+ // The scope passed in may not be a decl scope. Zip up the scope tree until
+ // we find one that is.
+ while ((S->getFlags() & Scope::DeclScope) == 0)
+ S = S->getParent();
+
// Verify that there isn't already something declared with this name in this
// scope.
if (Decl *PrevDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary, IdLoc, S)) {
OpenPOWER on IntegriCloud