[cfe-commits] r91155 - in /cfe/trunk: include/clang/Analysis/PathDiagnostic.h lib/Analysis/PathDiagnostic.cpp
Benjamin Kramer
benny.kra at googlemail.com
Fri Dec 11 13:09:28 PST 2009
Author: d0k
Date: Fri Dec 11 15:09:27 2009
New Revision: 91155
URL: http://llvm.org/viewvc/llvm-project?rev=91155&view=rev
Log:
Switch PathDiagnostic to StringRef.
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=91155&r1=91154&r2=91155&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/Analysis/PathDiagnostic.h Fri Dec 11 15:09:27 2009
@@ -179,9 +179,7 @@
PathDiagnosticPiece& operator=(const PathDiagnosticPiece &P);
protected:
- PathDiagnosticPiece(const std::string& s, Kind k, DisplayHint hint = Below);
-
- PathDiagnosticPiece(const char* s, Kind k, DisplayHint hint = Below);
+ PathDiagnosticPiece(llvm::StringRef s, Kind k, DisplayHint hint = Below);
PathDiagnosticPiece(Kind k, DisplayHint hint = Below);
@@ -242,7 +240,7 @@
PathDiagnosticLocation Pos;
public:
PathDiagnosticSpotPiece(const PathDiagnosticLocation &pos,
- const std::string& s,
+ llvm::StringRef s,
PathDiagnosticPiece::Kind k,
bool addPosRange = true)
: PathDiagnosticPiece(s, k), Pos(pos) {
@@ -261,11 +259,7 @@
public:
PathDiagnosticEventPiece(const PathDiagnosticLocation &pos,
- const std::string& s, bool addPosRange = true)
- : PathDiagnosticSpotPiece(pos, s, Event, addPosRange) {}
-
- PathDiagnosticEventPiece(const PathDiagnosticLocation &pos, const char* s,
- bool addPosRange = true)
+ llvm::StringRef s, bool addPosRange = true)
: PathDiagnosticSpotPiece(pos, s, Event, addPosRange) {}
~PathDiagnosticEventPiece();
@@ -280,14 +274,7 @@
public:
PathDiagnosticControlFlowPiece(const PathDiagnosticLocation &startPos,
const PathDiagnosticLocation &endPos,
- const std::string& s)
- : PathDiagnosticPiece(s, ControlFlow) {
- LPairs.push_back(PathDiagnosticLocationPair(startPos, endPos));
- }
-
- PathDiagnosticControlFlowPiece(const PathDiagnosticLocation &startPos,
- const PathDiagnosticLocation &endPos,
- const char* s)
+ llvm::StringRef s)
: PathDiagnosticPiece(s, ControlFlow) {
LPairs.push_back(PathDiagnosticLocationPair(startPos, endPos));
}
@@ -384,10 +371,8 @@
public:
PathDiagnostic();
- PathDiagnostic(const char* bugtype, const char* desc, const char* category);
-
- PathDiagnostic(const std::string& bugtype, const std::string& desc,
- const std::string& category);
+ PathDiagnostic(llvm::StringRef bugtype, llvm::StringRef desc,
+ llvm::StringRef category);
~PathDiagnostic();
@@ -398,8 +383,7 @@
typedef std::deque<std::string>::const_iterator meta_iterator;
meta_iterator meta_begin() const { return OtherDesc.begin(); }
meta_iterator meta_end() const { return OtherDesc.end(); }
- void addMeta(const std::string& s) { OtherDesc.push_back(s); }
- void addMeta(const char* s) { OtherDesc.push_back(s); }
+ void addMeta(llvm::StringRef s) { OtherDesc.push_back(s); }
PathDiagnosticLocation getLocation() const {
assert(Size > 0 && "getLocation() requires a non-empty PathDiagnostic.");
Modified: cfe/trunk/lib/Analysis/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PathDiagnostic.cpp?rev=91155&r1=91154&r2=91155&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/Analysis/PathDiagnostic.cpp Fri Dec 11 15:09:27 2009
@@ -36,30 +36,16 @@
return false;
}
-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 llvm::StringRef StripTrailingDots(llvm::StringRef s) {
+ for (llvm::StringRef::size_type i = s.size(); i != 0; --i)
+ if (s[i - 1] != '.')
+ return s.substr(0, i);
+ return "";
}
-static inline size_t GetNumCharsToLastNonPeriod(const std::string &s) {
- return s.empty () ? 0 : GetNumCharsToLastNonPeriod(&s[0]);
-}
-
-PathDiagnosticPiece::PathDiagnosticPiece(const std::string& s,
+PathDiagnosticPiece::PathDiagnosticPiece(llvm::StringRef s,
Kind k, DisplayHint hint)
- : str(s, 0, GetNumCharsToLastNonPeriod(s)), kind(k), Hint(hint) {}
-
-PathDiagnosticPiece::PathDiagnosticPiece(const char* s, Kind k,
- DisplayHint hint)
- : str(s, GetNumCharsToLastNonPeriod(s)), kind(k), Hint(hint) {}
+ : str(StripTrailingDots(s)), kind(k), Hint(hint) {}
PathDiagnosticPiece::PathDiagnosticPiece(Kind k, DisplayHint hint)
: kind(k), Hint(hint) {}
@@ -89,20 +75,12 @@
}
-PathDiagnostic::PathDiagnostic(const char* bugtype, const char* desc,
- const char* category)
- : Size(0),
- BugType(bugtype, GetNumCharsToLastNonPeriod(bugtype)),
- Desc(desc, GetNumCharsToLastNonPeriod(desc)),
- Category(category, GetNumCharsToLastNonPeriod(category)) {}
-
-PathDiagnostic::PathDiagnostic(const std::string& bugtype,
- const std::string& desc,
- const std::string& category)
+PathDiagnostic::PathDiagnostic(llvm::StringRef bugtype, llvm::StringRef desc,
+ llvm::StringRef category)
: Size(0),
- BugType(bugtype, 0, GetNumCharsToLastNonPeriod(bugtype)),
- Desc(desc, 0, GetNumCharsToLastNonPeriod(desc)),
- Category(category, 0, GetNumCharsToLastNonPeriod(category)) {}
+ BugType(StripTrailingDots(bugtype)),
+ Desc(StripTrailingDots(desc)),
+ Category(StripTrailingDots(category)) {}
void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
const DiagnosticInfo &Info) {
@@ -126,8 +104,7 @@
Info.FormatDiagnostic(StrC);
PathDiagnosticPiece *P =
- new PathDiagnosticEventPiece(Info.getLocation(),
- std::string(StrC.begin(), StrC.end()));
+ new PathDiagnosticEventPiece(Info.getLocation(), StrC.str());
for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i)
P->addRange(Info.getRange(i));
More information about the cfe-commits
mailing list