diff options
author | Chris Lattner <sabre@nondot.org> | 2010-04-06 18:06:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-04-06 18:06:18 +0000 |
commit | b019491b8d7b171cd0835ba34f3b28b24dfcc3e0 (patch) | |
tree | df8105db1abf53a82e43dbe4fa4c49d12299bc4f /include/llvm/Support/SourceMgr.h | |
parent | 98116f99b6bd766d98a650594d355dedc593d4d4 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100538 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/SourceMgr.h')
-rw-r--r-- | include/llvm/Support/SourceMgr.h | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/include/llvm/Support/SourceMgr.h b/include/llvm/Support/SourceMgr.h index 3e66762ae3..857d4d4d7b 100644 --- a/include/llvm/Support/SourceMgr.h +++ b/include/llvm/Support/SourceMgr.h @@ -148,6 +148,7 @@ private: /// 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; @@ -155,13 +156,23 @@ class SMDiagnostic { 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; } |