mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 19:31:58 +00:00
SourceMgr: Add ShowLine argument to PrintMessage, to allow suppressing the source line output.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89627 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
964ac01201
commit
4153982375
@ -120,7 +120,9 @@ public:
|
|||||||
///
|
///
|
||||||
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
||||||
/// prefixed to the message.
|
/// 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
|
/// GetMessage - Return an SMDiagnostic at the specified location with the
|
||||||
@ -128,8 +130,10 @@ public:
|
|||||||
///
|
///
|
||||||
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
||||||
/// prefixed to the message.
|
/// prefixed to the message.
|
||||||
|
/// @param ShowLine - Should the diagnostic show the source line.
|
||||||
SMDiagnostic GetMessage(SMLoc Loc,
|
SMDiagnostic GetMessage(SMLoc Loc,
|
||||||
const std::string &Msg, const char *Type) const;
|
const std::string &Msg, const char *Type,
|
||||||
|
bool ShowLine = true) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -143,12 +147,15 @@ class SMDiagnostic {
|
|||||||
std::string Filename;
|
std::string Filename;
|
||||||
int LineNo, ColumnNo;
|
int LineNo, ColumnNo;
|
||||||
std::string Message, LineContents;
|
std::string Message, LineContents;
|
||||||
|
unsigned ShowLine : 1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SMDiagnostic() : LineNo(0), ColumnNo(0) {}
|
SMDiagnostic() : LineNo(0), ColumnNo(0) {}
|
||||||
SMDiagnostic(const std::string &FN, int Line, int Col,
|
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),
|
: Filename(FN), LineNo(Line), ColumnNo(Col), Message(Msg),
|
||||||
LineContents(LineStr) {}
|
LineContents(LineStr), ShowLine(showline) {}
|
||||||
|
|
||||||
void Print(const char *ProgName, raw_ostream &S);
|
void Print(const char *ProgName, raw_ostream &S);
|
||||||
};
|
};
|
||||||
|
@ -136,7 +136,7 @@ void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
|
|||||||
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
||||||
/// prefixed to the message.
|
/// prefixed to the message.
|
||||||
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const std::string &Msg,
|
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
|
// First thing to do: find the current buffer containing the specified
|
||||||
// location.
|
// location.
|
||||||
@ -145,17 +145,21 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const std::string &Msg,
|
|||||||
|
|
||||||
MemoryBuffer *CurMB = getBufferInfo(CurBuf).Buffer;
|
MemoryBuffer *CurMB = getBufferInfo(CurBuf).Buffer;
|
||||||
|
|
||||||
|
|
||||||
// Scan backward to find the start of the line.
|
// Scan backward to find the start of the line.
|
||||||
const char *LineStart = Loc.getPointer();
|
const char *LineStart = Loc.getPointer();
|
||||||
while (LineStart != CurMB->getBufferStart() &&
|
while (LineStart != CurMB->getBufferStart() &&
|
||||||
LineStart[-1] != '\n' && LineStart[-1] != '\r')
|
LineStart[-1] != '\n' && LineStart[-1] != '\r')
|
||||||
--LineStart;
|
--LineStart;
|
||||||
// Get the end of the line.
|
|
||||||
const char *LineEnd = Loc.getPointer();
|
std::string LineStr;
|
||||||
while (LineEnd != CurMB->getBufferEnd() &&
|
if (ShowLine) {
|
||||||
LineEnd[0] != '\n' && LineEnd[0] != '\r')
|
// Get the end of the line.
|
||||||
++LineEnd;
|
const char *LineEnd = Loc.getPointer();
|
||||||
|
while (LineEnd != CurMB->getBufferEnd() &&
|
||||||
|
LineEnd[0] != '\n' && LineEnd[0] != '\r')
|
||||||
|
++LineEnd;
|
||||||
|
LineStr = std::string(LineStart, LineEnd);
|
||||||
|
}
|
||||||
|
|
||||||
std::string PrintedMsg;
|
std::string PrintedMsg;
|
||||||
if (Type) {
|
if (Type) {
|
||||||
@ -164,21 +168,20 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const std::string &Msg,
|
|||||||
}
|
}
|
||||||
PrintedMsg += Msg;
|
PrintedMsg += Msg;
|
||||||
|
|
||||||
// Print out the line.
|
|
||||||
return SMDiagnostic(CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
|
return SMDiagnostic(CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
|
||||||
Loc.getPointer()-LineStart, PrintedMsg,
|
Loc.getPointer()-LineStart, PrintedMsg,
|
||||||
std::string(LineStart, LineEnd));
|
LineStr, ShowLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg,
|
void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg,
|
||||||
const char *Type) const {
|
const char *Type, bool ShowLine) const {
|
||||||
raw_ostream &OS = errs();
|
raw_ostream &OS = errs();
|
||||||
|
|
||||||
int CurBuf = FindBufferContainingLoc(Loc);
|
int CurBuf = FindBufferContainingLoc(Loc);
|
||||||
assert(CurBuf != -1 && "Invalid or unspecified location!");
|
assert(CurBuf != -1 && "Invalid or unspecified location!");
|
||||||
PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
|
PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
|
||||||
|
|
||||||
GetMessage(Loc, Msg, Type).Print(0, OS);
|
GetMessage(Loc, Msg, Type, ShowLine).Print(0, OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -202,7 +205,7 @@ void SMDiagnostic::Print(const char *ProgName, raw_ostream &S) {
|
|||||||
|
|
||||||
S << ": " << Message << '\n';
|
S << ": " << Message << '\n';
|
||||||
|
|
||||||
if (LineNo != -1 && ColumnNo != -1) {
|
if (LineNo != -1 && ColumnNo != -1 && ShowLine) {
|
||||||
S << LineContents << '\n';
|
S << LineContents << '\n';
|
||||||
|
|
||||||
// Print out spaces/tabs before the caret.
|
// Print out spaces/tabs before the caret.
|
||||||
|
Loading…
Reference in New Issue
Block a user