[cfe-commits] r66893 - in /cfe/trunk: include/clang/Parse/Scope.h lib/Sema/Sema.cpp lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaStmt.cpp test/Sema/block-labels.c
Douglas Gregor
dgregor at apple.com
Fri Mar 13 08:49:27 PDT 2009
On Mar 13, 2009, at 8:38 AM, Steve Naroff wrote:
> Author: snaroff
> Date: Fri Mar 13 10:38:40 2009
> New Revision: 66893
>
> URL: http://llvm.org/viewvc/llvm-project?rev=66893&view=rev
> Log:
> Remove ActiveScope (revert http://llvm.org/viewvc/llvm-project?view=rev&revision=65694
> and http://llvm.org/viewvc/llvm-project?view=rev&revision=66741).
>
> Will replace with something better today...
Thank you for working on this!
- Doug
> Modified:
> cfe/trunk/include/clang/Parse/Scope.h
> cfe/trunk/lib/Sema/Sema.cpp
> cfe/trunk/lib/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaStmt.cpp
> cfe/trunk/test/Sema/block-labels.c
>
> Modified: cfe/trunk/include/clang/Parse/Scope.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Scope.h?rev=66893&r1=66892&r2=66893&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/Parse/Scope.h (original)
> +++ cfe/trunk/include/clang/Parse/Scope.h Fri Mar 13 10:38:40 2009
> @@ -16,7 +16,6 @@
>
> #include "clang/Parse/Action.h"
> #include "llvm/ADT/SmallPtrSet.h"
> -#include "llvm/ADT/DenseSet.h"
>
> namespace clang {
>
> @@ -131,12 +130,6 @@
> UsingDirectivesTy UsingDirectives;
>
> public:
> - /// LabelMap - This is a mapping from label identifiers to the
> LabelStmt for
> - /// it (which acts like the label decl in some ways). Forward
> referenced
> - /// labels have a LabelStmt created for them with a null location
> & SubStmt.
> - typedef llvm::DenseMap<IdentifierInfo*, Action::StmtTy*>
> LabelMapTy;
> - LabelMapTy LabelMap;
> -
> Scope(Scope *Parent, unsigned ScopeFlags) {
> Init(Parent, ScopeFlags);
> }
> @@ -308,7 +301,6 @@
> if (Flags & TemplateParamScope) TemplateParamParent = this;
> DeclsInScope.clear();
> UsingDirectives.clear();
> - LabelMap.clear();
> Entity = 0;
> }
> };
>
> Modified: cfe/trunk/lib/Sema/Sema.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=66893&r1=66892&r2=66893&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/Sema.cpp (original)
> +++ cfe/trunk/lib/Sema/Sema.cpp Fri Mar 13 10:38:40 2009
> @@ -169,8 +169,6 @@
>
> StdNamespace = 0;
> TUScope = 0;
> - ActiveScope = 0;
> -
> if (getLangOptions().CPlusPlus)
> FieldCollector.reset(new CXXFieldCollector());
>
>
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=66893&r1=66892&r2=66893&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Fri Mar 13 10:38:40 2009
> @@ -104,14 +104,15 @@
> /// the active block object that represents it.
> BlockSemaInfo *CurBlock;
>
> - /// ActiveScope - If inside of a function, method, or block
> definition,
> - /// this contains a pointer to the active scope that represents it.
> - Scope *ActiveScope;
> -
> /// PackContext - Manages the stack for #pragma pack. An alignment
> /// of 0 indicates default alignment.
> void *PackContext; // Really a "PragmaPackStack*"
>
> + /// LabelMap - This is a mapping from label identifiers to the
> LabelStmt for
> + /// it (which acts like the label decl in some ways). Forward
> referenced
> + /// labels have a LabelStmt created for them with a null location
> & SubStmt.
> + llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
> +
> llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
>
> /// ExtVectorDecls - This is a list all the extended vector types.
> This allows
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=66893&r1=66892&r2=66893&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar 13 10:38:40 2009
> @@ -2631,8 +2631,6 @@
> Decl *decl = static_cast<Decl*>(D);
> FunctionDecl *FD = cast<FunctionDecl>(decl);
>
> - ActiveScope = FnBodyScope;
> -
> // See if this is a redefinition.
> const FunctionDecl *Definition;
> if (FD->getBody(Definition)) {
> @@ -2784,29 +2782,17 @@
> return 0;
> }
> PopDeclContext();
> -
> - // FIXME: Temporary hack to workaround nested C++ functions. For
> example:
> - // class C2 {
> - // void f() {
> - // class LC1 {
> - // int m() { return 1; }
> - // };
> - // }
> - // };
> - if (ActiveScope == 0)
> - return D;
> -
> // Verify and clean out per-function state.
>
> - bool HaveLabels = !ActiveScope->LabelMap.empty();
> + bool HaveLabels = !LabelMap.empty();
> // Check goto/label use.
> - for (Scope::LabelMapTy::iterator I = ActiveScope->LabelMap.begin(),
> - E = ActiveScope->LabelMap.end(); I != E; ++I) {
> + for (llvm::DenseMap<IdentifierInfo*, LabelStmt*>::iterator
> + I = LabelMap.begin(), E = LabelMap.end(); I != E; ++I) {
> // Verify that we have no forward references left. If so, there
> was a goto
> // or address of a label taken, but no definition of it. Label
> fwd
> // definitions are indicated with a null substmt.
> - LabelStmt *L = static_cast<LabelStmt*>(I->second);
> - if (L->getSubStmt() == 0) {
> + if (I->second->getSubStmt() == 0) {
> + LabelStmt *L = I->second;
> // Emit error.
> Diag(L->getIdentLoc(), diag::err_undeclared_label_use) << L-
> >getName();
>
> @@ -2828,8 +2814,7 @@
> }
> }
> }
> - // This reset is for both functions and methods.
> - ActiveScope = 0;
> + LabelMap.clear();
>
> if (!Body) return D;
>
>
> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=66893&r1=66892&r2=66893&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Mar 13 10:38:40 2009
> @@ -37,8 +37,6 @@
> // Allow all of Sema to see that we are entering a method
> definition.
> PushDeclContext(FnBodyScope, MDecl);
>
> - ActiveScope = FnBodyScope;
> -
> // Create Decl objects for each parameter, entrring them in the
> scope for
> // binding to their use.
>
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=66893&r1=66892&r2=66893&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar 13 10:38:40 2009
> @@ -4336,20 +4336,13 @@
> SourceLocation LabLoc,
> IdentifierInfo *LabelII) {
> // Look up the record for this label identifier.
> - llvm::DenseMap<IdentifierInfo*, Action::StmtTy*>::iterator I =
> - ActiveScope->LabelMap.find(LabelII);
> + LabelStmt *&LabelDecl = LabelMap[LabelII];
>
> - LabelStmt *LabelDecl;
> -
> // If we haven't seen this label yet, create a forward reference. It
> // will be validated and/or cleaned up in ActOnFinishFunctionBody.
> - if (I == ActiveScope->LabelMap.end()) {
> + if (LabelDecl == 0)
> LabelDecl = new (Context) LabelStmt(LabLoc, LabelII, 0);
>
> - ActiveScope->LabelMap.insert(std::make_pair(LabelII, LabelDecl));
> - } else
> - LabelDecl = static_cast<LabelStmt *>(I->second);
> -
> // Create the AST node. The address of a label always has type
> 'void*'.
> return new (Context) AddrLabelExpr(OpLoc, LabLoc, LabelDecl,
> Context.getPointerType
> (Context.VoidTy));
> @@ -4539,7 +4532,6 @@
> // Add BSI to CurBlock.
> BSI->PrevBlockInfo = CurBlock;
> CurBlock = BSI;
> - ActiveScope = BlockScope;
>
> BSI->ReturnType = 0;
> BSI->TheScope = BlockScope;
> @@ -4617,13 +4609,6 @@
> // Ensure that CurBlock is deleted.
> llvm::OwningPtr<BlockSemaInfo> CC(CurBlock);
>
> - // Before popping CurBlock, set ActiveScope to this scope's
> function
> - // or block parent.
> - ActiveScope = CurBlock->TheScope->getParent();
> - while (ActiveScope &&
> - ((ActiveScope->getFlags() & (Scope::FnScope |
> Scope::BlockScope)) == 0))
> - ActiveScope = ActiveScope->getParent();
> -
> // Pop off CurBlock, handle nested blocks.
> CurBlock = CurBlock->PrevBlockInfo;
>
> @@ -4641,13 +4626,6 @@
>
> PopDeclContext();
>
> - // Before popping CurBlock, set ActiveScope to this scope's
> function
> - // or block parent.
> - ActiveScope = CurBlock->TheScope->getParent();
> - while (ActiveScope &&
> - ((ActiveScope->getFlags() & (Scope::FnScope |
> Scope::BlockScope)) == 0))
> - ActiveScope = ActiveScope->getParent();
> -
> // Pop off CurBlock, handle nested blocks.
> CurBlock = CurBlock->PrevBlockInfo;
>
>
> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=66893&r1=66892&r2=66893&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Mar 13 10:38:40 2009
> @@ -169,19 +169,12 @@
> Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
> SourceLocation ColonLoc, StmtArg subStmt) {
> Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
> -
> // Look up the record for this label identifier.
> - Scope::LabelMapTy::iterator I = ActiveScope->LabelMap.find(II);
> + LabelStmt *&LabelDecl = LabelMap[II];
>
> - LabelStmt *LabelDecl;
> -
> // If not forward referenced or defined already, just create a new
> LabelStmt.
> - if (I == ActiveScope->LabelMap.end()) {
> - LabelDecl = new (Context) LabelStmt(IdentLoc, II, SubStmt);
> - ActiveScope->LabelMap.insert(std::make_pair(II, LabelDecl));
> - return Owned(LabelDecl);
> - } else
> - LabelDecl = static_cast<LabelStmt *>(I->second);
> + if (LabelDecl == 0)
> + return Owned(LabelDecl = new (Context) LabelStmt(IdentLoc, II,
> SubStmt));
>
> assert(LabelDecl->getID() == II && "Label mismatch!");
>
> @@ -683,16 +676,11 @@
> return StmtError(Diag(GotoLoc, diag::err_goto_in_block));
>
> // Look up the record for this label identifier.
> - Scope::LabelMapTy::iterator I = ActiveScope->LabelMap.find
> (LabelII);
> + LabelStmt *&LabelDecl = LabelMap[LabelII];
>
> - LabelStmt *LabelDecl;
> -
> - // If not forward referenced or defined already, just create a
> new LabelStmt.
> - if (I == ActiveScope->LabelMap.end()) {
> + // If we haven't seen this label yet, create a forward reference.
> + if (LabelDecl == 0)
> LabelDecl = new (Context) LabelStmt(LabelLoc, LabelII, 0);
> - ActiveScope->LabelMap.insert(std::make_pair(LabelII, LabelDecl));
> - } else
> - LabelDecl = static_cast<LabelStmt *>(I->second);
>
> return Owned(new (Context) GotoStmt(LabelDecl, GotoLoc, LabelLoc));
> }
>
> Modified: cfe/trunk/test/Sema/block-labels.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-labels.c?rev=66893&r1=66892&r2=66893&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/test/Sema/block-labels.c (original)
> +++ cfe/trunk/test/Sema/block-labels.c Fri Mar 13 10:38:40 2009
> @@ -1,17 +0,0 @@
> -// RUN: clang %s -verify -fblocks -fsyntax-only
> -
> -int a() {
> - A:if (1) xx();
> - return ^{A:return 1;}();
> -}
> -int b() {
> - A: return ^{int a; A:return 1;}();
> -}
> -
> -int d() {
> - A: return ^{int a; A: a = ^{int a; A:return 1;}() + ^{int b;
> A:return 2;}(); return a; }();
> -}
> -
> -int c() {
> - goto A; return ^{ A:return 1;}(); // expected-error {{use of
> undeclared label 'A'}}
> -}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list