[cfe-commits] r140162 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h lib/StaticAnalyzer/Core/PathDiagnostic.cpp
Anna Zaks
ganna at apple.com
Tue Sep 20 11:23:52 PDT 2011
Author: zaks
Date: Tue Sep 20 13:23:52 2011
New Revision: 140162
URL: http://llvm.org/viewvc/llvm-project?rev=140162&view=rev
Log:
[analyzer] Refactor PathDiagnosticLocation: Use PointerUnion of LocationContext and AnalysisContext to support creation of PathDiagnosticLocations for checkers which no context sensitivity.
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=140162&r1=140161&r2=140162&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h Tue Sep 20 13:23:52 2011
@@ -16,6 +16,7 @@
#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/PointerUnion.h"
#include <deque>
#include <iterator>
#include <string>
@@ -23,6 +24,7 @@
namespace clang {
+class AnalysisContext;
class BinaryOperator;
class CompoundStmt;
class Decl;
@@ -88,6 +90,9 @@
PathDiagnosticRange() : isPoint(false) {}
};
+typedef llvm::PointerUnion<const LocationContext*, AnalysisContext*>
+ LocationOrAnalysisContext;
+
class PathDiagnosticLocation {
private:
enum Kind { RangeK, SingleLocK, StmtK, DeclK } K;
@@ -98,8 +103,10 @@
FullSourceLoc Loc;
PathDiagnosticRange Range;
- FullSourceLoc genLocation(const LocationContext *LC=0) const;
- PathDiagnosticRange genRange(const LocationContext *LC=0) const;
+ FullSourceLoc
+ genLocation(LocationOrAnalysisContext LAC = (AnalysisContext*)0) const;
+ PathDiagnosticRange
+ genRange(LocationOrAnalysisContext LAC = (AnalysisContext*)0) const;
public:
PathDiagnosticLocation()
@@ -119,9 +126,9 @@
PathDiagnosticLocation(const Stmt *s,
const SourceManager &sm,
- const LocationContext *lc)
+ LocationOrAnalysisContext lac)
: K(StmtK), S(s), D(0), SM(&sm),
- Loc(genLocation(lc)), Range(genRange(lc)) {}
+ Loc(genLocation(lac)), Range(genRange(lac)) {}
PathDiagnosticLocation(const Decl *d, const SourceManager &sm)
@@ -132,7 +139,7 @@
// Create a location for the beginning of the statement.
static PathDiagnosticLocation createBeginStmt(const Stmt *S,
const SourceManager &SM,
- const LocationContext *LC);
+ LocationOrAnalysisContext LAC);
/// Create the location for the operator of the binary expression.
/// Assumes the statement has a valid location.
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=140162&r1=140161&r2=140162&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Tue Sep 20 13:23:52 2011
@@ -131,16 +131,23 @@
//===----------------------------------------------------------------------===//
static SourceLocation getValidSourceLocation(const Stmt* S,
- const LocationContext *LC) {
+ LocationOrAnalysisContext LAC) {
SourceLocation L = S->getLocStart();
+ assert(!LAC.isNull() && "A valid LocationContext or AnalysisContext should "
+ "be passed to PathDiagnosticLocation upon creation.");
// S might be a temporary statement that does not have a location in the
// source code, so find an enclosing statement and use it's location.
if (!L.isValid()) {
- const ParentMap &PM = LC->getParentMap();
+
+ ParentMap *PM = 0;
+ if (LAC.is<const LocationContext*>())
+ PM = &LAC.get<const LocationContext*>()->getParentMap();
+ else
+ PM = &LAC.get<AnalysisContext*>()->getParentMap();
while (!L.isValid()) {
- S = PM.getParent(S);
+ S = PM->getParent(S);
L = S->getLocStart();
}
}
@@ -151,8 +158,8 @@
PathDiagnosticLocation
PathDiagnosticLocation::createBeginStmt(const Stmt *S,
const SourceManager &SM,
- const LocationContext *LC) {
- return PathDiagnosticLocation(getValidSourceLocation(S, LC),
+ LocationOrAnalysisContext LAC) {
+ return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
SM, SingleLocK);
}
@@ -246,7 +253,7 @@
}
FullSourceLoc
- PathDiagnosticLocation::genLocation(const LocationContext *LC) const {
+ PathDiagnosticLocation::genLocation(LocationOrAnalysisContext LAC) const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in
// case we add more cases.
@@ -255,7 +262,7 @@
case RangeK:
break;
case StmtK:
- return FullSourceLoc(getValidSourceLocation(S, LC),
+ return FullSourceLoc(getValidSourceLocation(S, LAC),
const_cast<SourceManager&>(*SM));
case DeclK:
return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM));
@@ -265,7 +272,7 @@
}
PathDiagnosticRange
- PathDiagnosticLocation::genRange(const LocationContext *LC) const {
+ PathDiagnosticLocation::genRange(LocationOrAnalysisContext LAC) const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in
// case we add more cases.
@@ -300,7 +307,7 @@
case Stmt::BinaryConditionalOperatorClass:
case Stmt::ConditionalOperatorClass:
case Stmt::ObjCForCollectionStmtClass: {
- SourceLocation L = getValidSourceLocation(S, LC);
+ SourceLocation L = getValidSourceLocation(S, LAC);
return SourceRange(L, L);
}
}
More information about the cfe-commits
mailing list