]> granicus.if.org Git - clang/commitdiff
- Implement PathDiagnosticLocation::asLocation.
authorTed Kremenek <kremenek@apple.com>
Thu, 26 Mar 2009 21:39:39 +0000 (21:39 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 26 Mar 2009 21:39:39 +0000 (21:39 +0000)
- Switch PathDiagnosticEventPiece and PathDiagnosticMacroPiece to use
  PathDiagnosticLocation.

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

include/clang/Analysis/PathDiagnostic.h
lib/Analysis/PathDiagnostic.cpp

index abf37f70799b832e3e89a749963862025cbde050..f647be9d6dc97dfc75f8e897d3e031184de6d693 100644 (file)
@@ -271,25 +271,27 @@ public:
   
 class PathDiagnosticSpotPiece : public PathDiagnosticPiece {
 private:
-  FullSourceLoc Pos;
+  PathDiagnosticLocation Pos;
 public:
-  PathDiagnosticSpotPiece(FullSourceLoc pos, const std::string& s,
+  PathDiagnosticSpotPiece(const PathDiagnosticLocation &pos,
+                          const std::string& s,
                           PathDiagnosticPiece::Kind k)
   : PathDiagnosticPiece(s, k), Pos(pos) {
-    assert(Pos.isValid() &&
+    assert(Pos.asLocation().isValid() &&
            "PathDiagnosticSpotPiece's must have a valid location.");
   }  
 
-  FullSourceLoc getLocation() const { return Pos; }
+  FullSourceLoc getLocation() const { return Pos.asLocation(); }
 };
   
 class PathDiagnosticEventPiece : public PathDiagnosticSpotPiece {
 
 public:
-  PathDiagnosticEventPiece(FullSourceLoc pos, const std::string& s)
+  PathDiagnosticEventPiece(const PathDiagnosticLocation &pos,
+                           const std::string& s)
     : PathDiagnosticSpotPiece(pos, s, Event) {}
   
-  PathDiagnosticEventPiece(FullSourceLoc pos, const char* s)
+  PathDiagnosticEventPiece(const PathDiagnosticLocation &pos, const char* s)
     : PathDiagnosticSpotPiece(pos, s, Event) {}
   
   ~PathDiagnosticEventPiece();
@@ -332,7 +334,7 @@ public:
 class PathDiagnosticMacroPiece : public PathDiagnosticSpotPiece {
   std::vector<PathDiagnosticPiece*> SubPieces;
 public:
-  PathDiagnosticMacroPiece(FullSourceLoc pos)
+  PathDiagnosticMacroPiece(const PathDiagnosticLocation &pos)
     : PathDiagnosticSpotPiece(pos, "", Macro) {}
   
   ~PathDiagnosticMacroPiece();
index 0ccb9006451e60e9aab17fc94fbf0d9c29c9ee7b..940a9e2d984b400ad15375c04e7035d294aaba29 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/PathDiagnostic.h"
+#include "clang/AST/Expr.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Casting.h"
 #include <sstream>
@@ -133,3 +134,17 @@ void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
 
   HandlePathDiagnostic(D);  
 }
+
+//===----------------------------------------------------------------------===//
+// PathDiagnosticLocation methods.
+//===----------------------------------------------------------------------===//
+
+FullSourceLoc PathDiagnosticLocation::asLocation() const {
+  switch (K) {
+    case SingleLoc:
+    case Range:
+      return FullSourceLoc(R.getBegin(), const_cast<SourceManager&>(SM));
+    case Statement:
+      return FullSourceLoc(S->getLocStart(), const_cast<SourceManager&>(SM));
+  }
+}