[llvm-branch-commits] [llvm-branch] r101508 - in /llvm/branches/Apple/Morbo: include/llvm/Support/IRReader.h include/llvm/Support/SourceMgr.h lib/AsmParser/Parser.cpp lib/Support/SourceMgr.cpp
Daniel Dunbar
daniel at zuster.org
Fri Apr 16 11:33:35 PDT 2010
Author: ddunbar
Date: Fri Apr 16 13:33:35 2010
New Revision: 101508
URL: http://llvm.org/viewvc/llvm-project?rev=101508&view=rev
Log:
enhance SMDiagnostic to also maintain a pointer to the SourceMgr. Add a simplified constructor for clients that don't have locations like "file not found" errors.
Modified:
llvm/branches/Apple/Morbo/include/llvm/Support/IRReader.h
llvm/branches/Apple/Morbo/include/llvm/Support/SourceMgr.h
llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp
llvm/branches/Apple/Morbo/lib/Support/SourceMgr.cpp
Modified: llvm/branches/Apple/Morbo/include/llvm/Support/IRReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/include/llvm/Support/IRReader.h?rev=101508&r1=101507&r2=101508&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/include/llvm/Support/IRReader.h (original)
+++ llvm/branches/Apple/Morbo/include/llvm/Support/IRReader.h Fri Apr 16 13:33:35 2010
@@ -38,8 +38,7 @@
std::string ErrMsg;
Module *M = getLazyBitcodeModule(Buffer, Context, &ErrMsg);
if (M == 0) {
- Err = SMDiagnostic(SMLoc(), Buffer->getBufferIdentifier(), -1, -1,
- ErrMsg, "");
+ Err = SMDiagnostic(Buffer->getBufferIdentifier(), ErrMsg);
// ParseBitcodeFile does not take ownership of the Buffer in the
// case of an error.
delete Buffer;
@@ -60,8 +59,8 @@
std::string ErrMsg;
MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrMsg);
if (F == 0) {
- Err = SMDiagnostic(SMLoc(), Filename, -1, -1,
- "Could not open input file '" + Filename + "'", "");
+ Err = SMDiagnostic(Filename,
+ "Could not open input file '" + Filename + "'");
return 0;
}
@@ -82,8 +81,7 @@
// ParseBitcodeFile does not take ownership of the Buffer.
delete Buffer;
if (M == 0)
- Err = SMDiagnostic(SMLoc(), Buffer->getBufferIdentifier(),
- -1, -1, ErrMsg, "");
+ Err = SMDiagnostic(Buffer->getBufferIdentifier(), ErrMsg);
return M;
}
@@ -99,8 +97,8 @@
std::string ErrMsg;
MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrMsg);
if (F == 0) {
- Err = SMDiagnostic(SMLoc(), Filename, -1, -1,
- "Could not open input file '" + Filename + "'", "");
+ Err = SMDiagnostic(Filename,
+ "Could not open input file '" + Filename + "'");
return 0;
}
Modified: llvm/branches/Apple/Morbo/include/llvm/Support/SourceMgr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/include/llvm/Support/SourceMgr.h?rev=101508&r1=101507&r2=101508&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/include/llvm/Support/SourceMgr.h (original)
+++ llvm/branches/Apple/Morbo/include/llvm/Support/SourceMgr.h Fri Apr 16 13:33:35 2010
@@ -142,6 +142,7 @@
/// SMDiagnostic - Instances of this class encapsulate one diagnostic report,
/// allowing printing to a raw_ostream as a caret diagnostic.
class SMDiagnostic {
+ const SourceMgr *SM;
SMLoc Loc;
std::string Filename;
int LineNo, ColumnNo;
@@ -149,13 +150,23 @@
unsigned ShowLine : 1;
public:
- SMDiagnostic() : LineNo(0), ColumnNo(0), ShowLine(0) {}
- SMDiagnostic(SMLoc L, const std::string &FN, int Line, int Col,
+ // Null diagnostic.
+ SMDiagnostic() : SM(0), LineNo(0), ColumnNo(0), ShowLine(0) {}
+ // Diagnostic with no location (e.g. file not found, command line arg error).
+ SMDiagnostic(const std::string &filename, const std::string &Msg,
+ bool showline = true)
+ : SM(0), Loc(), Filename(filename), LineNo(-1), ColumnNo(-1),
+ Message(Msg), LineContents(""), ShowLine(showline) {}
+
+ // Diagnostic with a location.
+ SMDiagnostic(const SourceMgr &sm, SMLoc L, const std::string &FN,
+ int Line, int Col,
const std::string &Msg, const std::string &LineStr,
bool showline = true)
- : Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Message(Msg),
+ : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Message(Msg),
LineContents(LineStr), ShowLine(showline) {}
+ const SourceMgr *getSourceMgr() const { return SM; }
SMLoc getLoc() const { return Loc; }
const std::string getFilename() { return Filename; }
int getLineNo() const { return LineNo; }
Modified: llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp?rev=101508&r1=101507&r2=101508&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp Fri Apr 16 13:33:35 2010
@@ -44,9 +44,9 @@
std::string ErrorStr;
MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
if (F == 0) {
- Err = SMDiagnostic(SMLoc(), "", -1, -1,
+ Err = SMDiagnostic(Filename,
"Could not open input file '" + Filename + "': " +
- ErrorStr, "");
+ ErrorStr);
return 0;
}
Modified: llvm/branches/Apple/Morbo/lib/Support/SourceMgr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/Support/SourceMgr.cpp?rev=101508&r1=101507&r2=101508&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/Support/SourceMgr.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/Support/SourceMgr.cpp Fri Apr 16 13:33:35 2010
@@ -168,7 +168,7 @@
}
PrintedMsg += Msg;
- return SMDiagnostic(Loc,
+ return SMDiagnostic(*this, Loc,
CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
Loc.getPointer()-LineStart, PrintedMsg,
LineStr, ShowLine);
More information about the llvm-branch-commits
mailing list