[cfe-commits] r66799 - in /cfe/trunk: include/clang/Lex/PPCallbacks.h lib/Lex/PPMacroExpansion.cpp

Chris Lattner sabre at nondot.org
Thu Mar 12 10:31:44 PDT 2009


Author: lattner
Date: Thu Mar 12 12:31:43 2009
New Revision: 66799

URL: http://llvm.org/viewvc/llvm-project?rev=66799&view=rev
Log:
add a callback for macro expansion, based on a patch by Paolo Bolzoni!

Modified:
    cfe/trunk/include/clang/Lex/PPCallbacks.h
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=66799&r1=66798&r2=66799&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Thu Mar 12 12:31:43 2009
@@ -21,6 +21,7 @@
 namespace clang {
   class SourceLocation;
   class IdentifierInfo;
+  class MacroInfo;
     
 /// PPCallbacks - This interface provides a way to observe the actions of the
 /// preprocessor as it does its thing.  Clients can define their hooks here to
@@ -54,6 +55,10 @@
                              const std::string &Str) {
   }
   
+  /// MacroExpands - This is called Preprocessor::HandleMacroExpandedIdentifier
+  /// when a macro invocation is found.
+  virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
+  }
 };
 
 }  // end namespace clang

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=66799&r1=66798&r2=66799&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu Mar 12 12:31:43 2009
@@ -150,6 +150,8 @@
 /// expanded as a macro, handle it and return the next token as 'Identifier'.
 bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, 
                                                  MacroInfo *MI) {
+  if (Callbacks) Callbacks->MacroExpands(Identifier, MI);
+  
   // If this is a macro exapnsion in the "#if !defined(x)" line for the file,
   // then the macro could expand to different things in other contexts, we need
   // to disable the optimization in this case.





More information about the cfe-commits mailing list