From 928e9096cb65d240b20c43ffdb9decf2f2a4888c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 12 Apr 2009 01:39:54 +0000 Subject: [PATCH] add a ppcallback hook for macro definitions. llvm-svn: 68883 --- clang/include/clang/Lex/PPCallbacks.h | 9 +++++++-- clang/lib/Lex/PPDirectives.cpp | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h index cd7c5e42156f..d2e3f353cbfd 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -55,10 +55,15 @@ public: const std::string &Str) { } - /// MacroExpands - This is called Preprocessor::HandleMacroExpandedIdentifier - /// when a macro invocation is found. + /// MacroExpands - This is called by + /// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is + /// found. virtual void MacroExpands(const Token &Id, const MacroInfo* MI) { } + + /// MacroDefined - This hook is called whenever a macro definition is seen. + virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) { + } }; } // end namespace clang diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index ba321a7f6730..52f673c6d3a3 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1402,6 +1402,10 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { } setMacroInfo(MacroNameTok.getIdentifierInfo(), MI); + + // If the callbacks want to know, tell them about the macro definition. + if (Callbacks) + Callbacks->MacroDefined(MacroNameTok.getIdentifierInfo(), MI); } /// HandleUndefDirective - Implements #undef.