Create PathDiagnosticCallEnter and PathDiagnosticCallExit, to remark calls in PathDiagnostics from other events.  This will
have potential uses later.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149960 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
index 30b1332..9516fce 100644
--- a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
+++ b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
@@ -261,7 +261,7 @@
 
 class PathDiagnosticPiece {
 public:
-  enum Kind { ControlFlow, Event, Macro };
+  enum Kind { ControlFlow, Event, Macro, CallEnter, CallExit };
   enum DisplayHint { Above, Below };
 
 private:
@@ -356,6 +356,32 @@
     return P->getKind() == Event;
   }
 };
+  
+class PathDiagnosticCallEnterPiece : public PathDiagnosticSpotPiece {
+public:
+  PathDiagnosticCallEnterPiece(const PathDiagnosticLocation &pos,
+                              StringRef s)
+    : PathDiagnosticSpotPiece(pos, s, CallEnter, false) {}
+  
+  ~PathDiagnosticCallEnterPiece();
+  
+  static inline bool classof(const PathDiagnosticPiece *P) {
+    return P->getKind() == CallEnter;
+  }  
+};
+
+class PathDiagnosticCallExitPiece : public PathDiagnosticSpotPiece {
+public:
+  PathDiagnosticCallExitPiece(const PathDiagnosticLocation &pos,
+                             StringRef s)
+  : PathDiagnosticSpotPiece(pos, s, CallExit, false) {}
+  
+  ~PathDiagnosticCallExitPiece();
+  
+  static inline bool classof(const PathDiagnosticPiece *P) {
+    return P->getKind() == CallExit;
+  }  
+};
 
 class PathDiagnosticControlFlowPiece : public PathDiagnosticPiece {
   std::vector<PathDiagnosticLocationPair> LPairs;
diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index c0804e7..3ea08cd 100644
--- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -758,6 +758,10 @@
       Out << "Entering call to block";
     else if (const NamedDecl *ND = dyn_cast<NamedDecl>(callee))
       Out << "Entering call to '" << ND->getNameAsString() << "'";
+    StringRef msg = Out.str();
+    if (msg.empty())
+      return 0;
+    return new PathDiagnosticCallEnterPiece(pos, msg);
   }
   else if (const CallExit *CExit = dyn_cast<CallExit>(&PP)) {
     const Decl *caller = CExit->getLocationContext()->getParent()->getDecl();
@@ -765,15 +769,9 @@
     if (const NamedDecl *ND = dyn_cast<NamedDecl>(caller))
       Out << "Returning to '" << ND->getNameAsString() << "'";
     else
-      Out << "Returning to caller"; 
+      Out << "Returning to caller";
+    return new PathDiagnosticCallExitPiece(pos, Out.str());
   }
-  
-  if (!pos.isValid())
-    return 0;
-    
-  StringRef msg = Out.str();
-  if (msg.empty())
-    return 0;
 
-  return new PathDiagnosticEventPiece(pos, msg);
+  return 0;
 } 
diff --git a/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 933e15c..2b3dcdc 100644
--- a/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -334,6 +334,8 @@
 
   const char *Kind = 0;
   switch (P.getKind()) {
+  case PathDiagnosticPiece::CallEnter:
+  case PathDiagnosticPiece::CallExit:
   case PathDiagnosticPiece::Event:  Kind = "Event"; break;
   case PathDiagnosticPiece::ControlFlow: Kind = "Control"; break;
     // Setting Kind to "Control" is intentional.
diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index c0bb180..0d2c2e8 100644
--- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -52,6 +52,8 @@
 
 PathDiagnosticPiece::~PathDiagnosticPiece() {}
 PathDiagnosticEventPiece::~PathDiagnosticEventPiece() {}
+PathDiagnosticCallEnterPiece::~PathDiagnosticCallEnterPiece() {}
+PathDiagnosticCallExitPiece::~PathDiagnosticCallExitPiece() {}
 PathDiagnosticControlFlowPiece::~PathDiagnosticControlFlowPiece() {}
 
 PathDiagnosticMacroPiece::~PathDiagnosticMacroPiece() {
diff --git a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index cc8c315..89b44c1 100644
--- a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -275,8 +275,10 @@
     ReportControlFlow(o, cast<PathDiagnosticControlFlowPiece>(P), FM, SM,
                       LangOpts, indent);
     break;
+  case PathDiagnosticPiece::CallEnter:
+  case PathDiagnosticPiece::CallExit:
   case PathDiagnosticPiece::Event:
-    ReportEvent(o, cast<PathDiagnosticEventPiece>(P), FM, SM, LangOpts,
+    ReportEvent(o, cast<PathDiagnosticSpotPiece>(P), FM, SM, LangOpts,
                 indent);
     break;
   case PathDiagnosticPiece::Macro: