[cfe-commits] r65574 - in /cfe/trunk: include/clang/Analysis/PathDiagnostic.h lib/Analysis/PathDiagnostic.cpp
Ted Kremenek
kremenek at apple.com
Thu Feb 26 13:30:32 PST 2009
Author: kremenek
Date: Thu Feb 26 15:30:32 2009
New Revision: 65574
URL: http://llvm.org/viewvc/llvm-project?rev=65574&view=rev
Log:
PathDiagnosticPiece now automatically strips off trailing periods in diagnostic messages.
Modified:
cfe/trunk/include/clang/Analysis/PathDiagnostic.h
cfe/trunk/lib/Analysis/PathDiagnostic.cpp
Modified: cfe/trunk/include/clang/Analysis/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathDiagnostic.h?rev=65574&r1=65573&r2=65574&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/Analysis/PathDiagnostic.h Thu Feb 26 15:30:32 2009
@@ -29,21 +29,19 @@
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; }
Modified: cfe/trunk/lib/Analysis/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PathDiagnostic.cpp?rev=65574&r1=65573&r2=65574&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/Analysis/PathDiagnostic.cpp Thu Feb 26 15:30:32 2009
@@ -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;
}
More information about the cfe-commits
mailing list