give the SourceMgr object a cookie.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100504 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-04-06 00:33:43 +00:00
parent 8f0f480a10
commit 214aa8a2cf
2 changed files with 9 additions and 4 deletions

View File

@@ -35,7 +35,8 @@ public:
/// DiagHandlerTy - Clients that want to handle their own diagnostics in a /// DiagHandlerTy - Clients that want to handle their own diagnostics in a
/// custom way can register a function pointer+context as a diagnostic /// custom way can register a function pointer+context as a diagnostic
/// handler. It gets called each time PrintMessage is invoked. /// handler. It gets called each time PrintMessage is invoked.
typedef void (*DiagHandlerTy)(const SMDiagnostic&, void *Context); typedef void (*DiagHandlerTy)(const SMDiagnostic&, void *Context,
unsigned LocCookie);
private: private:
struct SrcBuffer { struct SrcBuffer {
/// Buffer - The memory buffer for the file. /// Buffer - The memory buffer for the file.
@@ -59,6 +60,7 @@ private:
DiagHandlerTy DiagHandler; DiagHandlerTy DiagHandler;
void *DiagContext; void *DiagContext;
unsigned DiagLocCookie;
SourceMgr(const SourceMgr&); // DO NOT IMPLEMENT SourceMgr(const SourceMgr&); // DO NOT IMPLEMENT
void operator=(const SourceMgr&); // DO NOT IMPLEMENT void operator=(const SourceMgr&); // DO NOT IMPLEMENT
@@ -71,10 +73,12 @@ public:
} }
/// setDiagHandler - Specify a diagnostic handler to be invoked every time /// setDiagHandler - Specify a diagnostic handler to be invoked every time
/// PrintMessage is called. /// PrintMessage is called. Ctx and Cookie are passed into the handler when
void setDiagHandler(DiagHandlerTy DH, void *Ctx = 0) { /// it is invoked.
void setDiagHandler(DiagHandlerTy DH, void *Ctx = 0, unsigned Cookie = 0) {
DiagHandler = DH; DiagHandler = DH;
DiagContext = Ctx; DiagContext = Ctx;
DiagLocCookie = Cookie;
} }
const SrcBuffer &getBufferInfo(unsigned i) const { const SrcBuffer &getBufferInfo(unsigned i) const {

View File

@@ -178,7 +178,8 @@ void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg,
const char *Type, bool ShowLine) const { const char *Type, bool ShowLine) const {
// Report the message with the diagnostic handler if present. // Report the message with the diagnostic handler if present.
if (DiagHandler) { if (DiagHandler) {
DiagHandler(GetMessage(Loc, Msg, Type, ShowLine), DiagContext); DiagHandler(GetMessage(Loc, Msg, Type, ShowLine),
DiagContext, DiagLocCookie);
return; return;
} }