forked from OSchip/llvm-project
parent
2942150df0
commit
4dab76a752
|
@ -179,9 +179,7 @@ private:
|
|||
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 @@ private:
|
|||
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 @@ class PathDiagnosticEventPiece : public PathDiagnosticSpotPiece {
|
|||
|
||||
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 @@ class PathDiagnosticControlFlowPiece : public PathDiagnosticPiece {
|
|||
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 @@ class PathDiagnostic : public llvm::FoldingSetNode {
|
|||
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 @@ public:
|
|||
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.");
|
||||
|
|
|
@ -36,30 +36,16 @@ bool PathDiagnosticMacroPiece::containsEvent() const {
|
|||
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 @@ void PathDiagnostic::resetPath(bool deletePieces) {
|
|||
}
|
||||
|
||||
|
||||
PathDiagnostic::PathDiagnostic(const char* bugtype, const char* desc,
|
||||
const char* category)
|
||||
PathDiagnostic::PathDiagnostic(llvm::StringRef bugtype, llvm::StringRef desc,
|
||||
llvm::StringRef 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)
|
||||
: 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 @@ void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
|
|||
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));
|
||||
|
|
Loading…
Reference in New Issue