Will replace with something better today...


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66893 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Steve Naroff 2009-03-13 15:38:40 +00:00
Родитель 610e81d6b7
Коммит caaacecb2b
8 изменённых файлов: 19 добавлений и 96 удалений

Просмотреть файл

@ -16,7 +16,6 @@
#include "clang/Parse/Action.h" #include "clang/Parse/Action.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/DenseSet.h"
namespace clang { namespace clang {
@ -131,12 +130,6 @@ private:
UsingDirectivesTy UsingDirectives; UsingDirectivesTy UsingDirectives;
public: 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) { Scope(Scope *Parent, unsigned ScopeFlags) {
Init(Parent, ScopeFlags); Init(Parent, ScopeFlags);
} }
@ -308,7 +301,6 @@ public:
if (Flags & TemplateParamScope) TemplateParamParent = this; if (Flags & TemplateParamScope) TemplateParamParent = this;
DeclsInScope.clear(); DeclsInScope.clear();
UsingDirectives.clear(); UsingDirectives.clear();
LabelMap.clear();
Entity = 0; Entity = 0;
} }
}; };

Просмотреть файл

@ -169,8 +169,6 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
StdNamespace = 0; StdNamespace = 0;
TUScope = 0; TUScope = 0;
ActiveScope = 0;
if (getLangOptions().CPlusPlus) if (getLangOptions().CPlusPlus)
FieldCollector.reset(new CXXFieldCollector()); FieldCollector.reset(new CXXFieldCollector());

Просмотреть файл

@ -104,14 +104,15 @@ public:
/// the active block object that represents it. /// the active block object that represents it.
BlockSemaInfo *CurBlock; 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 /// PackContext - Manages the stack for #pragma pack. An alignment
/// of 0 indicates default alignment. /// of 0 indicates default alignment.
void *PackContext; // Really a "PragmaPackStack*" 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; llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
/// ExtVectorDecls - This is a list all the extended vector types. This allows /// ExtVectorDecls - This is a list all the extended vector types. This allows

Просмотреть файл

@ -2631,8 +2631,6 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) {
Decl *decl = static_cast<Decl*>(D); Decl *decl = static_cast<Decl*>(D);
FunctionDecl *FD = cast<FunctionDecl>(decl); FunctionDecl *FD = cast<FunctionDecl>(decl);
ActiveScope = FnBodyScope;
// See if this is a redefinition. // See if this is a redefinition.
const FunctionDecl *Definition; const FunctionDecl *Definition;
if (FD->getBody(Definition)) { if (FD->getBody(Definition)) {
@ -2784,29 +2782,17 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) {
return 0; return 0;
} }
PopDeclContext(); 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. // Verify and clean out per-function state.
bool HaveLabels = !ActiveScope->LabelMap.empty(); bool HaveLabels = !LabelMap.empty();
// Check goto/label use. // Check goto/label use.
for (Scope::LabelMapTy::iterator I = ActiveScope->LabelMap.begin(), for (llvm::DenseMap<IdentifierInfo*, LabelStmt*>::iterator
E = ActiveScope->LabelMap.end(); I != E; ++I) { I = LabelMap.begin(), E = LabelMap.end(); I != E; ++I) {
// Verify that we have no forward references left. If so, there was a goto // 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 // or address of a label taken, but no definition of it. Label fwd
// definitions are indicated with a null substmt. // definitions are indicated with a null substmt.
LabelStmt *L = static_cast<LabelStmt*>(I->second); if (I->second->getSubStmt() == 0) {
if (L->getSubStmt() == 0) { LabelStmt *L = I->second;
// Emit error. // Emit error.
Diag(L->getIdentLoc(), diag::err_undeclared_label_use) << L->getName(); Diag(L->getIdentLoc(), diag::err_undeclared_label_use) << L->getName();
@ -2828,8 +2814,7 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) {
} }
} }
} }
// This reset is for both functions and methods. LabelMap.clear();
ActiveScope = 0;
if (!Body) return D; if (!Body) return D;

Просмотреть файл

@ -37,8 +37,6 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclTy *D) {
// Allow all of Sema to see that we are entering a method definition. // Allow all of Sema to see that we are entering a method definition.
PushDeclContext(FnBodyScope, MDecl); PushDeclContext(FnBodyScope, MDecl);
ActiveScope = FnBodyScope;
// Create Decl objects for each parameter, entrring them in the scope for // Create Decl objects for each parameter, entrring them in the scope for
// binding to their use. // binding to their use.

Просмотреть файл

@ -4336,20 +4336,13 @@ Sema::ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc,
SourceLocation LabLoc, SourceLocation LabLoc,
IdentifierInfo *LabelII) { IdentifierInfo *LabelII) {
// Look up the record for this label identifier. // Look up the record for this label identifier.
llvm::DenseMap<IdentifierInfo*, Action::StmtTy*>::iterator I = LabelStmt *&LabelDecl = LabelMap[LabelII];
ActiveScope->LabelMap.find(LabelII);
LabelStmt *LabelDecl;
// If we haven't seen this label yet, create a forward reference. It // If we haven't seen this label yet, create a forward reference. It
// will be validated and/or cleaned up in ActOnFinishFunctionBody. // will be validated and/or cleaned up in ActOnFinishFunctionBody.
if (I == ActiveScope->LabelMap.end()) { if (LabelDecl == 0)
LabelDecl = new (Context) LabelStmt(LabLoc, LabelII, 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*'. // Create the AST node. The address of a label always has type 'void*'.
return new (Context) AddrLabelExpr(OpLoc, LabLoc, LabelDecl, return new (Context) AddrLabelExpr(OpLoc, LabLoc, LabelDecl,
Context.getPointerType(Context.VoidTy)); Context.getPointerType(Context.VoidTy));
@ -4539,7 +4532,6 @@ void Sema::ActOnBlockStart(SourceLocation CaretLoc, Scope *BlockScope) {
// Add BSI to CurBlock. // Add BSI to CurBlock.
BSI->PrevBlockInfo = CurBlock; BSI->PrevBlockInfo = CurBlock;
CurBlock = BSI; CurBlock = BSI;
ActiveScope = BlockScope;
BSI->ReturnType = 0; BSI->ReturnType = 0;
BSI->TheScope = BlockScope; BSI->TheScope = BlockScope;
@ -4617,13 +4609,6 @@ void Sema::ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) {
// Ensure that CurBlock is deleted. // Ensure that CurBlock is deleted.
llvm::OwningPtr<BlockSemaInfo> CC(CurBlock); 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. // Pop off CurBlock, handle nested blocks.
CurBlock = CurBlock->PrevBlockInfo; CurBlock = CurBlock->PrevBlockInfo;
@ -4641,13 +4626,6 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body,
PopDeclContext(); 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. // Pop off CurBlock, handle nested blocks.
CurBlock = CurBlock->PrevBlockInfo; CurBlock = CurBlock->PrevBlockInfo;

Просмотреть файл

@ -169,19 +169,12 @@ Action::OwningStmtResult
Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
SourceLocation ColonLoc, StmtArg subStmt) { SourceLocation ColonLoc, StmtArg subStmt) {
Stmt *SubStmt = static_cast<Stmt*>(subStmt.release()); Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
// Look up the record for this label identifier. // 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 not forward referenced or defined already, just create a new LabelStmt.
if (I == ActiveScope->LabelMap.end()) { if (LabelDecl == 0)
LabelDecl = new (Context) LabelStmt(IdentLoc, II, SubStmt); return Owned(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);
assert(LabelDecl->getID() == II && "Label mismatch!"); assert(LabelDecl->getID() == II && "Label mismatch!");
@ -683,16 +676,11 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
return StmtError(Diag(GotoLoc, diag::err_goto_in_block)); return StmtError(Diag(GotoLoc, diag::err_goto_in_block));
// Look up the record for this label identifier. // Look up the record for this label identifier.
Scope::LabelMapTy::iterator I = ActiveScope->LabelMap.find(LabelII); LabelStmt *&LabelDecl = LabelMap[LabelII];
LabelStmt *LabelDecl; // If we haven't seen this label yet, create a forward reference.
if (LabelDecl == 0)
// If not forward referenced or defined already, just create a new LabelStmt.
if (I == ActiveScope->LabelMap.end()) {
LabelDecl = new (Context) LabelStmt(LabelLoc, LabelII, 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)); return Owned(new (Context) GotoStmt(LabelDecl, GotoLoc, LabelLoc));
} }

Просмотреть файл

@ -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'}}
}