From ef70724e66d8ede0edbe260fbcdd9781688bb1fd Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Tue, 20 Sep 2011 23:27:32 +0000 Subject: [PATCH] [analyzer] Refactor PathDiagnosticLocation: Remove SourceRange member from PathDiagnosticLocation - FullSourceLoc Loc and PathDiagnosticRange Range are sufficient. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140206 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Core/BugReporter/PathDiagnostic.h | 18 ++++++++++-------- lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 13 +++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h index e7baae6293..dd1622b7fb 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h @@ -95,7 +95,6 @@ typedef llvm::PointerUnion class PathDiagnosticLocation { private: enum Kind { RangeK, SingleLocK, StmtK, DeclK } K; - SourceRange R; const Stmt *S; const Decl *D; const SourceManager *SM; @@ -104,14 +103,16 @@ private: PathDiagnosticLocation(SourceLocation L, const SourceManager &sm, Kind kind) - : K(kind), R(L, L), S(0), D(0), SM(&sm), - Loc(genLocation()), Range(genRange()) { - } + : K(kind), S(0), D(0), SM(&sm), + Loc(genLocation(L)), Range(genRange(L)) {} FullSourceLoc - genLocation(LocationOrAnalysisContext LAC = (AnalysisContext*)0) const; + genLocation(SourceLocation L = SourceLocation(), + LocationOrAnalysisContext LAC = (AnalysisContext*)0) const; + PathDiagnosticRange - genRange(LocationOrAnalysisContext LAC = (AnalysisContext*)0) const; + genRange(SourceLocation L = SourceLocation(), + LocationOrAnalysisContext LAC = (AnalysisContext*)0) const; public: /// Create an invalid location. @@ -124,7 +125,8 @@ public: const SourceManager &sm, LocationOrAnalysisContext lac) : K(StmtK), S(s), D(0), SM(&sm), - Loc(genLocation(lac)), Range(genRange(lac)) {} + Loc(genLocation(SourceLocation(), lac)), + Range(genRange(SourceLocation(), lac)) {} /// Create a location corresponding to the given declaration. @@ -192,7 +194,7 @@ public: const PathDiagnosticLocation &PDL); bool operator==(const PathDiagnosticLocation &X) const { - return K == X.K && R == X.R && S == X.S && D == X.D; + return K == X.K && Loc == X.Loc && Range == X.Range; } bool operator!=(const PathDiagnosticLocation &X) const { diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index 932689cf5c..6fbfddbfd7 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -228,7 +228,7 @@ PathDiagnosticLocation PathDiagnosticLocation::createSingleLocation( } FullSourceLoc - PathDiagnosticLocation::genLocation(LocationOrAnalysisContext LAC) const { + PathDiagnosticLocation::genLocation(SourceLocation L, 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. @@ -243,17 +243,17 @@ FullSourceLoc return FullSourceLoc(D->getLocation(), const_cast(*SM)); } - return FullSourceLoc(R.getBegin(), const_cast(*SM)); + return FullSourceLoc(L, const_cast(*SM)); } PathDiagnosticRange - PathDiagnosticLocation::genRange(LocationOrAnalysisContext LAC) const { + PathDiagnosticLocation::genRange(SourceLocation L, 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. switch (K) { case SingleLocK: - return PathDiagnosticRange(R, true); + return PathDiagnosticRange(SourceRange(L,L), true); case RangeK: break; case StmtK: { @@ -302,19 +302,16 @@ PathDiagnosticRange } } - return R; + return SourceRange(L,L); } 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;