diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-04-06 22:33:35 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-04-06 22:33:35 +0000 |
commit | fea5f5a1e8fe558d716ddeddf1aecf63f2e9a54f (patch) | |
tree | 6d4135cbfdbafb0087db9c9dcd23c2d11b5a6215 /lib/Analysis/PathDiagnostic.cpp | |
parent | fc479d793b5daa20bbf54651b83a90e77e907949 (diff) |
PathDiagnosticLocation now also wraps Decls.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68470 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/PathDiagnostic.cpp')
-rw-r--r-- | lib/Analysis/PathDiagnostic.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/lib/Analysis/PathDiagnostic.cpp b/lib/Analysis/PathDiagnostic.cpp index 69b11fb5da..da007c16ec 100644 --- a/lib/Analysis/PathDiagnostic.cpp +++ b/lib/Analysis/PathDiagnostic.cpp @@ -13,6 +13,8 @@ #include "clang/Analysis/PathDiagnostic.h" #include "clang/AST/Expr.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Casting.h" #include <sstream> @@ -144,11 +146,13 @@ FullSourceLoc PathDiagnosticLocation::asLocation() const { // Note that we want a 'switch' here so that the compiler can warn us in // case we add more cases. switch (K) { - case SingleLoc: - case Range: + case SingleLocK: + case RangeK: break; - case Statement: + case StmtK: return FullSourceLoc(S->getLocStart(), const_cast<SourceManager&>(*SM)); + case DeclK: + return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM)); } return FullSourceLoc(R.getBegin(), const_cast<SourceManager&>(*SM)); @@ -159,13 +163,39 @@ SourceRange PathDiagnosticLocation::asRange() const { // Note that we want a 'switch' here so that the compiler can warn us in // case we add more cases. switch (K) { - case SingleLoc: - case Range: + case SingleLocK: + case RangeK: break; - case Statement: + case StmtK: return S->getSourceRange(); + case DeclK: + if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) + return MD->getSourceRange(); + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) + return FD->getBody()->getSourceRange(); + else { + SourceLocation L = D->getLocation(); + return SourceRange(L, L); + } } return R; } +void PathDiagnosticLocation::flatten() { + if (K == StmtK) { + R = asRange(); + K = RangeK; + S = 0; + D = 0; + } + else if (K == DeclK) { + SourceLocation L = D->getLocation(); + R = SourceRange(L, L); + K = SingleLocK; + S = 0; + D = 0; + } +} + + |