From 8fc32d272bd57b0a59f61c874cb7b56d9005e89e Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 19 Nov 2010 00:19:15 +0000 Subject: [PATCH] Refactoring. Get FunctionScopeInfo to use DiagnosticErrorTrap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119764 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/ScopeInfo.h | 15 +++++++-------- lib/Sema/Sema.cpp | 16 +++++++--------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/clang/Sema/ScopeInfo.h b/include/clang/Sema/ScopeInfo.h index 50cfa9bb56..15d17306c9 100644 --- a/include/clang/Sema/ScopeInfo.h +++ b/include/clang/Sema/ScopeInfo.h @@ -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; diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 8c1d5f449c..ec7b61d32a 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -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() { -- 2.40.0