Refactoring. Get FunctionScopeInfo to use DiagnosticErrorTrap.

llvm-svn: 119764
This commit is contained in:
Argyrios Kyrtzidis 2010-11-19 00:19:15 +00:00
parent 1865342442
commit f51ec1d12b
2 changed files with 14 additions and 17 deletions

View File

@ -48,9 +48,8 @@ public:
/// \brief Whether this function contains any indirect gotos.
bool HasIndirectGoto;
/// \brief The number of errors that had occurred before starting this
/// function or block.
unsigned NumErrorsAtStartOfFunction;
/// \brief Used to determine if errors occurred in this function or block.
DiagnosticErrorTrap ErrorTrap;
/// LabelMap - This is a mapping from label identifiers to the LabelStmt for
/// it (which acts like the label decl in some ways). Forward referenced
@ -83,18 +82,18 @@ public:
(HasBranchProtectedScope && HasBranchIntoScope);
}
FunctionScopeInfo(unsigned NumErrors)
FunctionScopeInfo(Diagnostic &Diag)
: IsBlockInfo(false),
HasBranchProtectedScope(false),
HasBranchIntoScope(false),
HasIndirectGoto(false),
NumErrorsAtStartOfFunction(NumErrors) { }
ErrorTrap(Diag) { }
virtual ~FunctionScopeInfo();
/// \brief Clear out the information in this function scope, making it
/// suitable for reuse.
void Clear(unsigned NumErrors);
void Clear();
static bool classof(const FunctionScopeInfo *FSI) { return true; }
};
@ -118,8 +117,8 @@ public:
/// Its return type may be BuiltinType::Dependent.
QualType FunctionType;
BlockScopeInfo(unsigned NumErrors, Scope *BlockScope, BlockDecl *Block)
: FunctionScopeInfo(NumErrors), hasBlockDeclRefExprs(false),
BlockScopeInfo(Diagnostic &Diag, Scope *BlockScope, BlockDecl *Block)
: FunctionScopeInfo(Diag), hasBlockDeclRefExprs(false),
TheDecl(Block), TheScope(BlockScope)
{
IsBlockInfo = true;

View File

@ -39,7 +39,7 @@ using namespace sema;
FunctionScopeInfo::~FunctionScopeInfo() { }
void FunctionScopeInfo::Clear(unsigned NumErrors) {
void FunctionScopeInfo::Clear() {
HasBranchProtectedScope = false;
HasBranchIntoScope = false;
HasIndirectGoto = false;
@ -47,7 +47,7 @@ void FunctionScopeInfo::Clear(unsigned NumErrors) {
LabelMap.clear();
SwitchStack.clear();
Returns.clear();
NumErrorsAtStartOfFunction = NumErrors;
ErrorTrap.reset();
}
BlockScopeInfo::~BlockScopeInfo() { }
@ -154,7 +154,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
ExprEvalContexts.push_back(
ExpressionEvaluationContextRecord(PotentiallyEvaluated, 0));
FunctionScopes.push_back(new FunctionScopeInfo(Diags.getNumErrors()));
FunctionScopes.push_back(new FunctionScopeInfo(Diags));
}
void Sema::Initialize() {
@ -535,17 +535,16 @@ void Sema::PushFunctionScope() {
if (FunctionScopes.size() == 1) {
// Use the "top" function scope rather than having to allocate
// memory for a new scope.
FunctionScopes.back()->Clear(getDiagnostics().getNumErrors());
FunctionScopes.back()->Clear();
FunctionScopes.push_back(FunctionScopes.back());
return;
}
FunctionScopes.push_back(
new FunctionScopeInfo(getDiagnostics().getNumErrors()));
FunctionScopes.push_back(new FunctionScopeInfo(getDiagnostics()));
}
void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) {
FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics().getNumErrors(),
FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics(),
BlockScope, Block));
}
@ -559,8 +558,7 @@ void Sema::PopFunctionOrBlockScope() {
/// \brief Determine whether any errors occurred within this function/method/
/// block.
bool Sema::hasAnyErrorsInThisFunction() const {
return getCurFunction()->NumErrorsAtStartOfFunction
!= getDiagnostics().getNumErrors();
return getCurFunction()->ErrorTrap.hasErrorOccurred();
}
BlockScopeInfo *Sema::getCurBlock() {