Refactor 'PostStmt' and 'PreStmt' to subclass a common parent 'StmtPoint'.

Educate GRExprEngine::VisitGraph() about 'PreStmt'.

Mark the constructor of 'PostStmt' to be explicit, preventing implicit
conversions and the selection of the wrong 'generateNode' method in
GRStmtNodeBuilder.

Constify a bunch of arguments, which falls out of the changes to ProgramPoint.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76809 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp
index a691bb6..43e1e6c 100644
--- a/lib/Analysis/BugReporter.cpp
+++ b/lib/Analysis/BugReporter.cpp
@@ -40,7 +40,7 @@
 // Helper routines for walking the ExplodedGraph and fetching statements.
 //===----------------------------------------------------------------------===//
 
-static inline Stmt* GetStmt(ProgramPoint P) {
+static inline const Stmt* GetStmt(ProgramPoint P) {
   if (const PostStmt* PS = dyn_cast<PostStmt>(&P))
     return PS->getStmt();
   else if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P))
@@ -59,17 +59,17 @@
   return N->succ_empty() ? NULL : *(N->succ_begin());
 }
 
-static Stmt* GetPreviousStmt(const ExplodedNode<GRState>* N) {
+static const Stmt* GetPreviousStmt(const ExplodedNode<GRState>* N) {
   for (N = GetPredecessorNode(N); N; N = GetPredecessorNode(N))
-    if (Stmt *S = GetStmt(N->getLocation()))
+    if (const Stmt *S = GetStmt(N->getLocation()))
       return S;
   
   return 0;
 }
 
-static Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
+static const Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
   for (N = GetSuccessorNode(N); N; N = GetSuccessorNode(N))
-    if (Stmt *S = GetStmt(N->getLocation())) {
+    if (const Stmt *S = GetStmt(N->getLocation())) {
       // Check if the statement is '?' or '&&'/'||'.  These are "merges",
       // not actual statement points.
       switch (S->getStmtClass()) {
@@ -90,15 +90,17 @@
   return 0;
 }
 
-static inline Stmt* GetCurrentOrPreviousStmt(const ExplodedNode<GRState>* N) {  
-  if (Stmt *S = GetStmt(N->getLocation()))
+static inline const Stmt*
+GetCurrentOrPreviousStmt(const ExplodedNode<GRState>* N) {  
+  if (const Stmt *S = GetStmt(N->getLocation()))
     return S;
   
   return GetPreviousStmt(N);
 }
         
-static inline Stmt* GetCurrentOrNextStmt(const ExplodedNode<GRState>* N) {  
-  if (Stmt *S = GetStmt(N->getLocation()))
+static inline const Stmt*
+GetCurrentOrNextStmt(const ExplodedNode<GRState>* N) {  
+  if (const Stmt *S = GetStmt(N->getLocation()))
     return S;
           
   return GetNextStmt(N);
@@ -179,7 +181,7 @@
 
 PathDiagnosticLocation
 PathDiagnosticBuilder::ExecutionContinues(const ExplodedNode<GRState>* N) {
-  if (Stmt *S = GetNextStmt(N))
+  if (const Stmt *S = GetNextStmt(N))
     return PathDiagnosticLocation(S, getSourceManager());
 
   return FullSourceLoc(getCodeDecl().getBodyRBrace(), getSourceManager());
@@ -330,7 +332,7 @@
     if (!isa<PostStmt>(P))
       continue;
     
-    DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt());
+    const DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt());
     
     if (!DR)
       continue;
@@ -340,7 +342,7 @@
     if (X != Y)
       continue;
     
-    VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
+    const VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
     
     if (!VD)
       continue;
@@ -457,13 +459,13 @@
   
   llvm::SmallSet<SymbolRef, 10> AlreadyProcessed;
   const ExplodedNode<GRState>* N;
-  Stmt* S;
+  const Stmt* S;
   GRBugReporter& BR;
   PathDiagnostic& PD;
   
 public:
-  ScanNotableSymbols(const ExplodedNode<GRState>* n, Stmt* s, GRBugReporter& br,
-                     PathDiagnostic& pd)
+  ScanNotableSymbols(const ExplodedNode<GRState>* n, const Stmt* s,
+                     GRBugReporter& br, PathDiagnostic& pd)
   : N(n), S(s), BR(br), PD(pd) {}
   
   bool HandleBinding(StoreManager& SMgr, Store store,
@@ -523,7 +525,7 @@
           
         case Stmt::GotoStmtClass:
         case Stmt::IndirectGotoStmtClass: {          
-          Stmt* S = GetNextStmt(N);
+          const Stmt* S = GetNextStmt(N);
           
           if (!S)
             continue;
@@ -1199,14 +1201,15 @@
 BugReport::~BugReport() {}
 RangedBugReport::~RangedBugReport() {}
 
-Stmt* BugReport::getStmt(BugReporter& BR) const {  
+const Stmt* BugReport::getStmt(BugReporter& BR) const {  
   ProgramPoint ProgP = EndNode->getLocation();  
-  Stmt *S = NULL;
+  const Stmt *S = NULL;
   
   if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP)) {
     if (BE->getBlock() == &BR.getCFG()->getExit()) S = GetPreviousStmt(EndNode);
   }
-  if (!S) S = GetStmt(ProgP);  
+  if (!S)
+    S = GetStmt(ProgP);  
   
   return S;  
 }
@@ -1215,7 +1218,7 @@
 BugReport::getEndPath(BugReporterContext& BRC,
                       const ExplodedNode<GRState>* EndPathNode) {
   
-  Stmt* S = getStmt(BRC.getBugReporter());
+  const Stmt* S = getStmt(BRC.getBugReporter());
   
   if (!S)
     return NULL;
@@ -1238,7 +1241,7 @@
 void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
                           const SourceRange*& end) {  
   
-  if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
+  if (const Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
     R = E->getSourceRange();
     assert(R.isValid());
     beg = &R;
@@ -1250,9 +1253,9 @@
 
 SourceLocation BugReport::getLocation() const {  
   if (EndNode)
-    if (Stmt* S = GetCurrentOrPreviousStmt(EndNode)) {
+    if (const Stmt* S = GetCurrentOrPreviousStmt(EndNode)) {
       // For member expressions, return the location of the '.' or '->'.
-      if (MemberExpr* ME = dyn_cast<MemberExpr>(S))
+      if (const MemberExpr* ME = dyn_cast<MemberExpr>(S))
         return ME->getMemberLoc();
 
       return S->getLocStart();