diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AsmParser/LLLexer.cpp | 2 | ||||
-rw-r--r-- | lib/AsmParser/Parser.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 23 | ||||
-rw-r--r-- | lib/Support/SourceMgr.cpp | 38 | ||||
-rw-r--r-- | lib/TableGen/Error.cpp | 4 | ||||
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 2 |
6 files changed, 39 insertions, 32 deletions
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index d0dd98627b..91d6c6a26d 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -29,7 +29,7 @@ using namespace llvm; bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const { - ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error"); + ErrorInfo = SM.GetMessage(ErrorLoc, SourceMgr::DK_Error, Msg); return true; } diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index 59fb471f2b..21b7fd411e 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -44,7 +44,7 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, LLVMContext &Context) { OwningPtr<MemoryBuffer> File; if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) { - Err = SMDiagnostic(Filename, + Err = SMDiagnostic(Filename, SourceMgr::DK_Error, "Could not open input file: " + ec.message()); return 0; } diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 25f404c703..0be8f51f0c 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -171,10 +171,10 @@ private: void HandleMacroExit(); void PrintMacroInstantiations(); - void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type, + void PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Msg, ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(), bool ShowLine = true) const { - SrcMgr.PrintMessage(Loc, Msg, Type, Ranges, ShowLine); + SrcMgr.PrintMessage(Loc, Kind, Msg, Ranges, ShowLine); } static void DiagHandler(const SMDiagnostic &Diag, void *Context); @@ -392,21 +392,21 @@ void AsmParser::PrintMacroInstantiations() { // Print the active macro instantiation stack. for (std::vector<MacroInstantiation*>::const_reverse_iterator it = ActiveMacros.rbegin(), ie = ActiveMacros.rend(); it != ie; ++it) - PrintMessage((*it)->InstantiationLoc, "while in macro instantiation", - "note"); + PrintMessage((*it)->InstantiationLoc, SourceMgr::DK_Note, + "while in macro instantiation"); } bool AsmParser::Warning(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges) { if (FatalAssemblerWarnings) return Error(L, Msg, Ranges); - PrintMessage(L, Msg, "warning", Ranges); + PrintMessage(L, SourceMgr::DK_Warning, Msg, Ranges); PrintMacroInstantiations(); return false; } bool AsmParser::Error(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges) { HadError = true; - PrintMessage(L, Msg, "error", Ranges); + PrintMessage(L, SourceMgr::DK_Error, Msg, Ranges); PrintMacroInstantiations(); return true; } @@ -498,9 +498,9 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { // FIXME: We would really like to refer back to where the symbol was // first referenced for a source location. We need to add something // to track that. Currently, we just point to the end of the file. - PrintMessage(getLexer().getLoc(), "assembler local symbol '" + - Sym->getName() + "' not defined", "error", - ArrayRef<SMRange>(), false); + PrintMessage(getLexer().getLoc(), SourceMgr::DK_Error, + "assembler local symbol '" + Sym->getName() + + "' not defined"); } } @@ -1203,7 +1203,7 @@ bool AsmParser::ParseStatement() { } OS << "]"; - PrintMessage(IDLoc, OS.str(), "note"); + PrintMessage(IDLoc, SourceMgr::DK_Note, OS.str()); } // If parsing succeeded, match the instruction. @@ -1305,7 +1305,8 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) { SMDiagnostic NewDiag(*Diag.getSourceMgr(), Diag.getLoc(), Filename, LineNo, Diag.getColumnNo(), - Diag.getMessage(), Diag.getLineContents(), + Diag.getKind(), Diag.getMessage(), + Diag.getLineContents(), Diag.getRanges(), Diag.getShowLine()); NewDiag.print(0, OS); 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) diff --git a/lib/TableGen/Error.cpp b/lib/TableGen/Error.cpp index 5b2cbbfec4..5071ee77ac 100644 --- a/lib/TableGen/Error.cpp +++ b/lib/TableGen/Error.cpp @@ -21,11 +21,11 @@ namespace llvm { SourceMgr SrcMgr; void PrintError(SMLoc ErrorLoc, const Twine &Msg) { - SrcMgr.PrintMessage(ErrorLoc, Msg, "error"); + SrcMgr.PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg); } void PrintError(const char *Loc, const Twine &Msg) { - SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error"); + SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg); } void PrintError(const Twine &Msg) { diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index ebd1e0aa1b..3ed2c2c7e9 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -100,7 +100,7 @@ void LLVMContext::emitError(unsigned LocCookie, StringRef ErrorStr) { } // If we do have an error handler, we can report the error and keep going. - SMDiagnostic Diag("", "error: " + ErrorStr.str()); + SMDiagnostic Diag("", SourceMgr::DK_Error, ErrorStr.str()); pImpl->InlineAsmDiagHandler(Diag, pImpl->InlineAsmDiagContext, LocCookie); } |