From cd6d4b105ab4874e4a9bc9618d05eca86e5b7ff5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 21 Apr 2009 03:42:09 +0000 Subject: [PATCH] add a preprocessor callback function for #undef, patch by Alexei Svitkine! llvm-svn: 69656 --- clang/include/clang/Lex/PPCallbacks.h | 5 +++++ clang/lib/Lex/PPDirectives.cpp | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h index d2e3f353cbfd..ddd7415c2936 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -64,6 +64,11 @@ public: /// MacroDefined - This hook is called whenever a macro definition is seen. virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) { } + + /// MacroUndefined - This hook is called whenever a macro #undef is seen. + /// MI is released immediately following this callback. + virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI) { + } }; } // end namespace clang diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 15477b63d3a6..a6e1e7ee2ca0 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1466,7 +1466,11 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) { if (!MI->isUsed()) Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used); - + + // If the callbacks want to know, tell them about the macro #undef. + if (Callbacks) + Callbacks->MacroUndefined(MacroNameTok.getIdentifierInfo(), MI); + // Free macro definition. ReleaseMacroInfo(MI); setMacroInfo(MacroNameTok.getIdentifierInfo(), 0);