]> granicus.if.org Git - clang/commitdiff
add a preprocessor callback function for #undef, patch by
authorChris Lattner <sabre@nondot.org>
Tue, 21 Apr 2009 03:42:09 +0000 (03:42 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 21 Apr 2009 03:42:09 +0000 (03:42 +0000)
Alexei Svitkine!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69656 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/PPCallbacks.h
lib/Lex/PPDirectives.cpp

index d2e3f353cbfd3d8ed27361f296ffd0300faabf7a..ddd7415c293629135594308d64ad29169115ece1 100644 (file)
@@ -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
index 15477b63d3a6805e48ea0666041098c57e52f95c..a6e1e7ee2ca0435abd53b0df24abfd299cbe29ce 100644 (file)
@@ -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);