[cfe-commits] r119763 - in /cfe/trunk: include/clang/Basic/Diagnostic.h include/clang/Sema/Scope.h include/clang/Sema/Sema.h lib/Parse/Parser.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Nov 18 16:19:12 PST 2010


Author: akirtzidis
Date: Thu Nov 18 18:19:12 2010
New Revision: 119763

URL: http://llvm.org/viewvc/llvm-project?rev=119763&view=rev
Log:
Refactoring.
Move ErrorTrap from clang/Sema to clang/Basic as DiagnosticErrorTrap and use it in Scope.

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/include/clang/Sema/Scope.h
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Parse/Parser.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=119763&r1=119762&r2=119763&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Nov 18 18:19:12 2010
@@ -29,6 +29,7 @@
   class DeclContext;
   class LangOptions;
   class Preprocessor;
+  class DiagnosticErrorTrap;
 
 /// \brief Annotates a diagnostic with some code that should be
 /// inserted, removed, or replaced to fix the problem.
@@ -486,6 +487,7 @@
   friend class DiagnosticBuilder;
   friend class DiagnosticInfo;
   friend class PartialDiagnostic;
+  friend class DiagnosticErrorTrap;
   
   /// CurDiagLoc - This is the location of the current diagnostic that is in
   /// flight.
@@ -549,6 +551,27 @@
   friend class ASTWriter;
 };
 
+/// \brief RAII class that determines when any errors have occurred
+/// between the time the instance was created and the time it was
+/// queried.
+class DiagnosticErrorTrap {
+  Diagnostic &Diag;
+  unsigned PrevErrors;
+
+public:
+  explicit DiagnosticErrorTrap(Diagnostic &Diag)
+    : Diag(Diag), PrevErrors(Diag.NumErrors) {}
+
+  /// \brief Determine whether any errors have occurred since this
+  /// object instance was created.
+  bool hasErrorOccurred() const {
+    return Diag.NumErrors > PrevErrors;
+  }
+
+  // Set to initial state of "no errors occurred".
+  void reset() { PrevErrors = Diag.NumErrors; }
+};
+
 //===----------------------------------------------------------------------===//
 // DiagnosticBuilder
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/include/clang/Sema/Scope.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=119763&r1=119762&r2=119763&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Scope.h (original)
+++ cfe/trunk/include/clang/Sema/Scope.h Thu Nov 18 18:19:12 2010
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_SEMA_SCOPE_H
 #define LLVM_CLANG_SEMA_SCOPE_H
 
+#include "clang/Basic/Diagnostic.h"
 #include "llvm/ADT/SmallPtrSet.h"
 
 namespace clang {
@@ -131,11 +132,12 @@
   typedef llvm::SmallVector<UsingDirectiveDecl *, 2> UsingDirectivesTy;
   UsingDirectivesTy UsingDirectives;
 
-  /// \brief The number of errors at the start of the given scope.
-  unsigned NumErrorsAtStart;
+  /// \brief Used to determine if errors occurred in this scope.
+  DiagnosticErrorTrap ErrorTrap;
   
 public:
-  Scope(Scope *Parent, unsigned ScopeFlags) {
+  Scope(Scope *Parent, unsigned ScopeFlags, Diagnostic &Diag)
+    : ErrorTrap(Diag) {
     Init(Parent, ScopeFlags);
   }
 
@@ -214,13 +216,7 @@
   void* getEntity() const { return Entity; }
   void setEntity(void *E) { Entity = E; }
 
-  /// \brief Retrieve the number of errors that had been emitted when we
-  /// entered this scope.
-  unsigned getNumErrorsAtStart() const { return NumErrorsAtStart; }
-  
-  void setNumErrorsAtStart(unsigned NumErrors) {
-    NumErrorsAtStart = NumErrors;
-  }
+  bool hasErrorOccurred() const { return ErrorTrap.hasErrorOccurred(); }
                            
   /// isClassScope - Return true if this scope is a class/struct/union scope.
   bool isClassScope() const {
@@ -318,7 +314,7 @@
     DeclsInScope.clear();
     UsingDirectives.clear();
     Entity = 0;
-    NumErrorsAtStart = 0;
+    ErrorTrap.reset();
   }
 };
 

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=119763&r1=119762&r2=119763&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Nov 18 18:19:12 2010
@@ -3521,24 +3521,6 @@
     }
   };
 
-  /// \brief RAII class that determines when any errors have occurred
-  /// between the time the instance was created and the time it was
-  /// queried.
-  class ErrorTrap {
-    Sema &SemaRef;
-    unsigned PrevErrors;
-
-  public:
-    explicit ErrorTrap(Sema &SemaRef)
-      : SemaRef(SemaRef), PrevErrors(SemaRef.getDiagnostics().getNumErrors()) {}
-
-    /// \brief Determine whether any errors have occurred since this
-    /// object instance was created.
-    bool hasErrorOccurred() const {
-      return SemaRef.getDiagnostics().getNumErrors() > PrevErrors;
-    }
-  };
-
   /// \brief The current instantiation scope used to store local
   /// variables.
   LocalInstantiationScope *CurrentInstantiationScope;

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=119763&r1=119762&r2=119763&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Thu Nov 18 18:19:12 2010
@@ -305,9 +305,8 @@
     N->Init(getCurScope(), ScopeFlags);
     Actions.CurScope = N;
   } else {
-    Actions.CurScope = new Scope(getCurScope(), ScopeFlags);
+    Actions.CurScope = new Scope(getCurScope(), ScopeFlags, Diags);
   }
-  getCurScope()->setNumErrorsAtStart(Diags.getNumErrors());
 }
 
 /// ExitScope - Pop a scope off the scope stack.

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=119763&r1=119762&r2=119763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Nov 18 18:19:12 2010
@@ -696,7 +696,7 @@
     if (!D->getDeclName()) continue;
 
     // Diagnose unused variables in this scope.
-    if (S->getNumErrorsAtStart() == getDiagnostics().getNumErrors())
+    if (!S->hasErrorOccurred())
       DiagnoseUnusedDecl(D);
     
     // Remove this name from our lexical scope.

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=119763&r1=119762&r2=119763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Nov 18 18:19:12 2010
@@ -4365,7 +4365,7 @@
   assert(ClassDecl && "DefineImplicitDefaultConstructor - invalid constructor");
 
   ImplicitlyDefinedFunctionScope Scope(*this, Constructor);
-  ErrorTrap Trap(*this);
+  DiagnosticErrorTrap Trap(Diags);
   if (SetBaseOrMemberInitializers(Constructor, 0, 0, /*AnyErrors=*/false) ||
       Trap.hasErrorOccurred()) {
     Diag(CurrentLocation, diag::note_member_synthesized_at) 
@@ -4473,7 +4473,7 @@
 
   ImplicitlyDefinedFunctionScope Scope(*this, Destructor);
 
-  ErrorTrap Trap(*this);
+  DiagnosticErrorTrap Trap(Diags);
   MarkBaseAndMemberDestructorsReferenced(Destructor->getLocation(),
                                          Destructor->getParent());
 
@@ -4878,7 +4878,7 @@
   CopyAssignOperator->setUsed();
 
   ImplicitlyDefinedFunctionScope Scope(*this, CopyAssignOperator);
-  ErrorTrap Trap(*this);
+  DiagnosticErrorTrap Trap(Diags);
 
   // C++0x [class.copy]p30:
   //   The implicitly-defined or explicitly-defaulted copy assignment operator
@@ -5340,7 +5340,7 @@
   assert(ClassDecl && "DefineImplicitCopyConstructor - invalid constructor");
 
   ImplicitlyDefinedFunctionScope Scope(*this, CopyConstructor);
-  ErrorTrap Trap(*this);
+  DiagnosticErrorTrap Trap(Diags);
 
   if (SetBaseOrMemberInitializers(CopyConstructor, 0, 0, /*AnyErrors=*/false) ||
       Trap.hasErrorOccurred()) {





More information about the cfe-commits mailing list