diff options
author | Chris Lattner <sabre@nondot.org> | 2011-10-16 05:43:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-10-16 05:43:57 +0000 |
commit | 3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3 (patch) | |
tree | e7c36aeb6ce5e3a57764d841e5a0f603b9e12bef /lib/Support/SourceMgr.cpp | |
parent | d8b7aa26134d2abee777f745c32005e63dea2455 (diff) | |
download | llvm-3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3.tar.gz llvm-3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3.tar.bz2 llvm-3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3.tar.xz |
Make SMDiagnostic a little more sane. Instead of passing around note/warning/error as a
string, pass it around as an enum.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/SourceMgr.cpp')
-rw-r--r-- | lib/Support/SourceMgr.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp index ba2201816e..91cb25a60a 100644 --- a/lib/Support/SourceMgr.cpp +++ b/lib/Support/SourceMgr.cpp @@ -140,8 +140,8 @@ void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const { /// /// @param Type - If non-null, the kind of message (e.g., "error") which is /// prefixed to the message. -SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const Twine &Msg, - const char *Type, ArrayRef<SMRange> Ranges, +SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind, + const Twine &Msg, ArrayRef<SMRange> Ranges, bool ShowLine) const { // First thing to do: find the current buffer containing the specified @@ -164,12 +164,6 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const Twine &Msg, ++LineEnd; std::string LineStr(LineStart, LineEnd); - std::string PrintedMsg; - raw_string_ostream OS(PrintedMsg); - if (Type) - OS << Type << ": "; - OS << Msg; - // Convert any ranges to column ranges that only intersect the line of the // location. SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges; @@ -194,16 +188,18 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const Twine &Msg, return SMDiagnostic(*this, Loc, CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf), - Loc.getPointer()-LineStart, OS.str(), + Loc.getPointer()-LineStart, Kind, Msg.str(), LineStr, ColRanges, ShowLine); } -void SourceMgr::PrintMessage(SMLoc Loc, const Twine &Msg, - const char *Type, ArrayRef<SMRange> Ranges, +void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind, + const Twine &Msg, ArrayRef<SMRange> Ranges, bool ShowLine) const { + SMDiagnostic Diagnostic = GetMessage(Loc, Kind, Msg, Ranges, ShowLine); + // Report the message with the diagnostic handler if present. if (DiagHandler) { - DiagHandler(GetMessage(Loc, Msg, Type, Ranges, ShowLine), DiagContext); + DiagHandler(Diagnostic, DiagContext); return; } @@ -213,7 +209,7 @@ void SourceMgr::PrintMessage(SMLoc Loc, const Twine &Msg, assert(CurBuf != -1 && "Invalid or unspecified location!"); PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS); - GetMessage(Loc, Msg, Type, Ranges, ShowLine).print(0, OS); + Diagnostic.print(0, OS); } //===----------------------------------------------------------------------===// @@ -221,12 +217,15 @@ void SourceMgr::PrintMessage(SMLoc Loc, const Twine &Msg, //===----------------------------------------------------------------------===// SMDiagnostic::SMDiagnostic(const SourceMgr &sm, SMLoc L, const std::string &FN, - int Line, int Col, const std::string &Msg, + int Line, int Col, SourceMgr::DiagKind Kind, + const std::string &Msg, const std::string &LineStr, ArrayRef<std::pair<unsigned,unsigned> > Ranges, bool showline) - : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Message(Msg), - LineContents(LineStr), ShowLine(showline), Ranges(Ranges.vec()) {} + : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind), + Message(Msg), LineContents(LineStr), ShowLine(showline), + Ranges(Ranges.vec()) { +} void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const { @@ -247,6 +246,13 @@ void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const { S << ": "; } + switch (Kind) { + default: assert(0 && "Unknown diagnostic kind"); + case SourceMgr::DK_Error: S << "error: "; break; + case SourceMgr::DK_Warning: S << "warning: "; break; + case SourceMgr::DK_Note: S << "note: "; break; + } + S << Message << '\n'; if (LineNo == -1 || ColumnNo == -1 || !ShowLine) |