diff options
| author | Ted Kremenek <kremenek@apple.com> | 2009-02-26 21:30:32 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2009-02-26 21:30:32 +0000 |
| commit | e9817aaa0595eae687c06e3c9d9ecfe00a47aa0d (patch) | |
| tree | 8dcf90be189cf69bfd95ecb8db03d25df1d9439e /clang | |
| parent | f4c205b2fa5c73096c1228f9f653ba4f1a558d23 (diff) | |
| download | bcm5719-llvm-e9817aaa0595eae687c06e3c9d9ecfe00a47aa0d.tar.gz bcm5719-llvm-e9817aaa0595eae687c06e3c9d9ecfe00a47aa0d.zip | |
PathDiagnosticPiece now automatically strips off trailing periods in diagnostic messages.
llvm-svn: 65574
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Analysis/PathDiagnostic.h | 12 | ||||
| -rw-r--r-- | clang/lib/Analysis/PathDiagnostic.cpp | 27 |
2 files changed, 32 insertions, 7 deletions
diff --git a/clang/include/clang/Analysis/PathDiagnostic.h b/clang/include/clang/Analysis/PathDiagnostic.h index cee11c27b59..a77ff66001a 100644 --- a/clang/include/clang/Analysis/PathDiagnostic.h +++ b/clang/include/clang/Analysis/PathDiagnostic.h @@ -29,21 +29,19 @@ public: enum DisplayHint { Above, Below }; private: - FullSourceLoc Pos; - std::string str; + const FullSourceLoc Pos; + const std::string str; std::vector<CodeModificationHint> CodeModificationHints; - DisplayHint Hint; + const DisplayHint Hint; std::vector<SourceRange> ranges; public: PathDiagnosticPiece(FullSourceLoc pos, const std::string& s, - DisplayHint hint = Above) - : Pos(pos), str(s), Hint(hint) {} + DisplayHint hint = Above); PathDiagnosticPiece(FullSourceLoc pos, const char* s, - DisplayHint hint = Above) - : Pos(pos), str(s), Hint(hint) {} + DisplayHint hint = Above); const std::string& getString() const { return str; } diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp index 50ff523b81d..d1120ef2d16 100644 --- a/clang/lib/Analysis/PathDiagnostic.cpp +++ b/clang/lib/Analysis/PathDiagnostic.cpp @@ -15,7 +15,34 @@ #include "llvm/ADT/SmallString.h" #include <sstream> using namespace clang; + +static size_t GetNumCharsToLastNonPeriod(const char *s) { + const char *start = s; + const char *lastNonPeriod = 0; + + for ( ; *s != '\0' ; ++s) + if (*s != '.') lastNonPeriod = s; + + if (!lastNonPeriod) + return 0; + return (lastNonPeriod - start) + 1; +} + +static inline size_t GetNumCharsToLastNonPeriod(const std::string &s) { + return s.empty () ? 0 : GetNumCharsToLastNonPeriod(&s[0]); +} + +PathDiagnosticPiece::PathDiagnosticPiece(FullSourceLoc pos, + const std::string& s, + DisplayHint hint) + : Pos(pos), str(s, 0, GetNumCharsToLastNonPeriod(s)), Hint(hint) {} + +PathDiagnosticPiece::PathDiagnosticPiece(FullSourceLoc pos, + const char* s, + DisplayHint hint) + : Pos(pos), str(s, GetNumCharsToLastNonPeriod(s)), Hint(hint) {} + PathDiagnostic::~PathDiagnostic() { for (iterator I = begin(), E = end(); I != E; ++I) delete &*I; } |

