]> granicus.if.org Git - clang/commitdiff
Added new "BugReporterHelper" class which is used by BugReporter to emit
authorTed Kremenek <kremenek@apple.com>
Wed, 9 Apr 2008 00:20:43 +0000 (00:20 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 9 Apr 2008 00:20:43 +0000 (00:20 +0000)
checker-specific diagnostics.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49412 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/BugReporter.h
lib/Analysis/BugReporter.cpp

index a5af327195144d33fddab708ed6e6a76179ed746..7ff79fc53d87521883425ce717de5f6e67116a10 100644 (file)
@@ -46,6 +46,16 @@ public:
                          const SourceRange*& end) const;
 };
   
+class BugReporterHelper {
+public:
+  virtual ~BugReporterHelper() {}
+  
+  virtual PathDiagnosticPiece* VisitNode(ExplodedNode<ValueState>* N,
+                                         ExplodedNode<ValueState>* PrevN,
+                                         ExplodedGraph<GRExprEngine>& G,
+                                         ASTContext& Ctx) = 0;
+};
+  
 class BugReporter {
   llvm::SmallPtrSet<void*,10> CachedErrors;
   
@@ -56,7 +66,9 @@ public:
   void EmitPathWarning(Diagnostic& Diag, PathDiagnosticClient* PDC,
                        ASTContext& Ctx, const BugDescription& B,
                        ExplodedGraph<GRExprEngine>& G,
-                       ExplodedNode<ValueState>* N);
+                       ExplodedNode<ValueState>* N,
+                       BugReporterHelper** BegHelpers = NULL,
+                       BugReporterHelper** EndHelpers = NULL);
   
   void EmitWarning(Diagnostic& Diag, ASTContext& Ctx,
                    const BugDescription& B,
@@ -69,7 +81,9 @@ private:
   void GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
                               const BugDescription& B,
                               ExplodedGraph<GRExprEngine>& G,
-                              ExplodedNode<ValueState>* N);
+                              ExplodedNode<ValueState>* N,
+                              BugReporterHelper** BegHelpers = NULL,
+                              BugReporterHelper** EndHelpers = NULL);
 };
   
 } // end clang namespace
index 14f98fa1f4af90cc3521f0461af712a9eb3b0a96..66b1b04c9d0fa639e481ea4d103a3a3fdd4e8318 100644 (file)
@@ -83,7 +83,9 @@ void BugDescription::getRanges(const SourceRange*& beg,
 void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
                                          const BugDescription& B,
                                          ExplodedGraph<GRExprEngine>& G,
-                                         ExplodedNode<ValueState>* N) {
+                                         ExplodedNode<ValueState>* N,
+                                         BugReporterHelper** BegHelpers,
+                                         BugReporterHelper** EndHelpers) {
   
   if (PathDiagnosticPiece* Piece = B.getEndPath(Ctx,N))
     PD.push_back(Piece);
@@ -112,11 +114,15 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
   assert (NewN->getLocation() == N->getLocation());
   
   N = NewN;
-
-  while (!N->pred_empty()) {
+  
+  ExplodedNode<ValueState>* NextNode = N->pred_empty() 
+                                       ? NULL : *(N->pred_begin());
+  
+  while (NextNode) {
     
     ExplodedNode<ValueState>* LastNode = N;
-    N = *(N->pred_begin());
+    N = NextNode;    
+    NextNode = N->pred_empty() ? NULL : *(N->pred_begin());
     
     ProgramPoint P = N->getLocation();
     
@@ -171,7 +177,7 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
             case Stmt::DefaultStmtClass: {
               
               os << "Control jumps to the 'default' case at line "
-              << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
+                 << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
               
               break;
             }
@@ -284,7 +290,15 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
           break;
         }
       }
-    }  
+    }
+    else
+      for (BugReporterHelper** I = BegHelpers; I != EndHelpers; ++I) {
+
+        PathDiagnosticPiece* piece = (*I)->VisitNode(N, NextNode, G, Ctx);
+
+        if (piece)
+          PD.push_front(piece);
+      }
   }
 }
 
@@ -309,7 +323,9 @@ void BugReporter::EmitPathWarning(Diagnostic& Diag,
                                   ASTContext& Ctx,
                                   const BugDescription& B,
                                   ExplodedGraph<GRExprEngine>& G,
-                                  ExplodedNode<ValueState>* N) {
+                                  ExplodedNode<ValueState>* N,
+                                  BugReporterHelper** BegHelpers,
+                                  BugReporterHelper** EndHelpers) {
   
   if (!PDC) {
     EmitWarning(Diag, Ctx, B, N);
@@ -320,7 +336,7 @@ void BugReporter::EmitPathWarning(Diagnostic& Diag,
     return;
   
   PathDiagnostic D(B.getName());  
-  GeneratePathDiagnostic(D, Ctx, B, G, N);
+  GeneratePathDiagnostic(D, Ctx, B, G, N, BegHelpers, EndHelpers);
   
   if (!D.empty())  
     PDC->HandlePathDiagnostic(D);