]> granicus.if.org Git - clang/commitdiff
add a callback for macro expansion, based on a patch by Paolo Bolzoni!
authorChris Lattner <sabre@nondot.org>
Thu, 12 Mar 2009 17:31:43 +0000 (17:31 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 12 Mar 2009 17:31:43 +0000 (17:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66799 91177308-0d34-0410-b5e6-96231b3b80d8

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

index bf03bb81f22a41ed279989f4cb084813a5fa5e64..cd7c5e42156f07f977d73b57d700d402ee44fd7d 100644 (file)
@@ -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 @@ public:
                              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
index 84056c3f4b5b384cbe783651bb18522d2e7af4fd..712918b7c3b201dd2281a847573d1671837a1f88 100644 (file)
@@ -150,6 +150,8 @@ bool Preprocessor::isNextPPTokenLParen() {
 /// 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.