[llvm-commits] [llvm] r89627 - in /llvm/trunk: include/llvm/Support/SourceMgr.h lib/Support/SourceMgr.cpp
Daniel Dunbar
daniel at zuster.org
Sun Nov 22 14:08:00 PST 2009
Author: ddunbar
Date: Sun Nov 22 16:08:00 2009
New Revision: 89627
URL: http://llvm.org/viewvc/llvm-project?rev=89627&view=rev
Log:
SourceMgr: Add ShowLine argument to PrintMessage, to allow suppressing the source line output.
Modified:
llvm/trunk/include/llvm/Support/SourceMgr.h
llvm/trunk/lib/Support/SourceMgr.cpp
Modified: llvm/trunk/include/llvm/Support/SourceMgr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/SourceMgr.h?rev=89627&r1=89626&r2=89627&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/SourceMgr.h (original)
+++ llvm/trunk/include/llvm/Support/SourceMgr.h Sun Nov 22 16:08:00 2009
@@ -120,7 +120,9 @@
///
/// @param Type - If non-null, the kind of message (e.g., "error") which is
/// prefixed to the message.
- void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
+ /// @param ShowLine - Should the diagnostic show the source line.
+ void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type,
+ bool ShowLine = true) const;
/// GetMessage - Return an SMDiagnostic at the specified location with the
@@ -128,8 +130,10 @@
///
/// @param Type - If non-null, the kind of message (e.g., "error") which is
/// prefixed to the message.
+ /// @param ShowLine - Should the diagnostic show the source line.
SMDiagnostic GetMessage(SMLoc Loc,
- const std::string &Msg, const char *Type) const;
+ const std::string &Msg, const char *Type,
+ bool ShowLine = true) const;
private:
@@ -143,12 +147,15 @@
std::string Filename;
int LineNo, ColumnNo;
std::string Message, LineContents;
+ unsigned ShowLine : 1;
+
public:
SMDiagnostic() : LineNo(0), ColumnNo(0) {}
SMDiagnostic(const std::string &FN, int Line, int Col,
- const std::string &Msg, const std::string &LineStr)
+ const std::string &Msg, const std::string &LineStr,
+ bool showline = true)
: Filename(FN), LineNo(Line), ColumnNo(Col), Message(Msg),
- LineContents(LineStr) {}
+ LineContents(LineStr), ShowLine(showline) {}
void Print(const char *ProgName, raw_ostream &S);
};
Modified: llvm/trunk/lib/Support/SourceMgr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SourceMgr.cpp?rev=89627&r1=89626&r2=89627&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SourceMgr.cpp (original)
+++ llvm/trunk/lib/Support/SourceMgr.cpp Sun Nov 22 16:08:00 2009
@@ -136,7 +136,7 @@
/// @param Type - If non-null, the kind of message (e.g., "error") which is
/// prefixed to the message.
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const std::string &Msg,
- const char *Type) const {
+ const char *Type, bool ShowLine) const {
// First thing to do: find the current buffer containing the specified
// location.
@@ -144,18 +144,22 @@
assert(CurBuf != -1 && "Invalid or unspecified location!");
MemoryBuffer *CurMB = getBufferInfo(CurBuf).Buffer;
-
-
+
// Scan backward to find the start of the line.
const char *LineStart = Loc.getPointer();
- while (LineStart != CurMB->getBufferStart() &&
+ while (LineStart != CurMB->getBufferStart() &&
LineStart[-1] != '\n' && LineStart[-1] != '\r')
--LineStart;
- // Get the end of the line.
- const char *LineEnd = Loc.getPointer();
- while (LineEnd != CurMB->getBufferEnd() &&
- LineEnd[0] != '\n' && LineEnd[0] != '\r')
- ++LineEnd;
+
+ std::string LineStr;
+ if (ShowLine) {
+ // Get the end of the line.
+ const char *LineEnd = Loc.getPointer();
+ while (LineEnd != CurMB->getBufferEnd() &&
+ LineEnd[0] != '\n' && LineEnd[0] != '\r')
+ ++LineEnd;
+ LineStr = std::string(LineStart, LineEnd);
+ }
std::string PrintedMsg;
if (Type) {
@@ -163,22 +167,21 @@
PrintedMsg += ": ";
}
PrintedMsg += Msg;
-
- // Print out the line.
+
return SMDiagnostic(CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
Loc.getPointer()-LineStart, PrintedMsg,
- std::string(LineStart, LineEnd));
+ LineStr, ShowLine);
}
void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg,
- const char *Type) const {
+ const char *Type, bool ShowLine) const {
raw_ostream &OS = errs();
int CurBuf = FindBufferContainingLoc(Loc);
assert(CurBuf != -1 && "Invalid or unspecified location!");
PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
- GetMessage(Loc, Msg, Type).Print(0, OS);
+ GetMessage(Loc, Msg, Type, ShowLine).Print(0, OS);
}
//===----------------------------------------------------------------------===//
@@ -201,8 +204,8 @@
}
S << ": " << Message << '\n';
-
- if (LineNo != -1 && ColumnNo != -1) {
+
+ if (LineNo != -1 && ColumnNo != -1 && ShowLine) {
S << LineContents << '\n';
// Print out spaces/tabs before the caret.
More information about the llvm-commits
mailing list