- Implement PathDiagnosticLocation::asLocation.

- Switch PathDiagnosticEventPiece and PathDiagnosticMacroPiece to use
  PathDiagnosticLocation.

llvm-svn: 67774
This commit is contained in:
Ted Kremenek 2009-03-26 21:39:39 +00:00
parent 2d6a1dec5d
commit bade06e7d7
2 changed files with 24 additions and 7 deletions

View 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();

View 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));
}
}