summaryrefslogtreecommitdiff
path: root/include/llvm/Support/SourceMgr.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-04-06 00:26:48 +0000
committerChris Lattner <sabre@nondot.org>2010-04-06 00:26:48 +0000
commit8f0f480a10cd5b62914fd53611e696c5069fc62d (patch)
treeddb0af86b39e52ed6f6d7f931268d32a9f315816 /include/llvm/Support/SourceMgr.h
parenta03948633ae848af9cecce0a8042c7db4dac44d9 (diff)
downloadllvm-8f0f480a10cd5b62914fd53611e696c5069fc62d.tar.gz
llvm-8f0f480a10cd5b62914fd53611e696c5069fc62d.tar.bz2
llvm-8f0f480a10cd5b62914fd53611e696c5069fc62d.tar.xz
Give llvm::SourceMgr the ability to have a client-specified
diagnostic handler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100503 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/SourceMgr.h')
-rw-r--r--include/llvm/Support/SourceMgr.h31
1 files changed, 28 insertions, 3 deletions
diff --git a/include/llvm/Support/SourceMgr.h b/include/llvm/Support/SourceMgr.h
index 158e7c9f42..caa67c03c5 100644
--- a/include/llvm/Support/SourceMgr.h
+++ b/include/llvm/Support/SourceMgr.h
@@ -31,6 +31,12 @@ namespace llvm {
/// SourceMgr - This owns the files read by a parser, handles include stacks,
/// and handles diagnostic wrangling.
class SourceMgr {
+public:
+ /// DiagHandlerTy - Clients that want to handle their own diagnostics in a
+ /// custom way can register a function pointer+context as a diagnostic
+ /// handler. It gets called each time PrintMessage is invoked.
+ typedef void (*DiagHandlerTy)(const SMDiagnostic&, void *Context);
+private:
struct SrcBuffer {
/// Buffer - The memory buffer for the file.
MemoryBuffer *Buffer;
@@ -51,16 +57,26 @@ class SourceMgr {
/// is really private to SourceMgr.cpp.
mutable void *LineNoCache;
+ DiagHandlerTy DiagHandler;
+ void *DiagContext;
+
SourceMgr(const SourceMgr&); // DO NOT IMPLEMENT
void operator=(const SourceMgr&); // DO NOT IMPLEMENT
public:
- SourceMgr() : LineNoCache(0) {}
+ SourceMgr() : LineNoCache(0), DiagHandler(0), DiagContext(0) {}
~SourceMgr();
void setIncludeDirs(const std::vector<std::string> &Dirs) {
IncludeDirectories = Dirs;
}
+ /// setDiagHandler - Specify a diagnostic handler to be invoked every time
+ /// PrintMessage is called.
+ void setDiagHandler(DiagHandlerTy DH, void *Ctx = 0) {
+ DiagHandler = DH;
+ DiagContext = Ctx;
+ }
+
const SrcBuffer &getBufferInfo(unsigned i) const {
assert(i < Buffers.size() && "Invalid Buffer ID!");
return Buffers[i];
@@ -128,6 +144,7 @@ private:
/// SMDiagnostic - Instances of this class encapsulate one diagnostic report,
/// allowing printing to a raw_ostream as a caret diagnostic.
class SMDiagnostic {
+ SMLoc Loc;
std::string Filename;
int LineNo, ColumnNo;
std::string Message, LineContents;
@@ -135,12 +152,20 @@ class SMDiagnostic {
public:
SMDiagnostic() : LineNo(0), ColumnNo(0), ShowLine(0) {}
- SMDiagnostic(const std::string &FN, int Line, int Col,
+ SMDiagnostic(SMLoc L, const std::string &FN, int Line, int Col,
const std::string &Msg, const std::string &LineStr,
bool showline = true)
- : Filename(FN), LineNo(Line), ColumnNo(Col), Message(Msg),
+ : Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Message(Msg),
LineContents(LineStr), ShowLine(showline) {}
+ SMLoc getLoc() const { return Loc; }
+ const std::string getFilename() { return Filename; }
+ int getLineNo() const { return LineNo; }
+ int getColumnNo() const { return ColumnNo; }
+ const std::string &getMessage() const { return Message; }
+ const std::string &getLineContents() const { return LineContents; }
+ bool getShowLine() const { return ShowLine; }
+
void Print(const char *ProgName, raw_ostream &S) const;
};