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

Douglas Gregor dgregor at apple.com
Thu Oct 13 17:49:43 PDT 2011


Author: dgregor
Date: Thu Oct 13 19:49:43 2011
New Revision: 141926

URL: http://llvm.org/viewvc/llvm-project?rev=141926&view=rev
Log:
Add a preprocessor callback that is invoked every time the 'defined'
operator is seen, from Jason Haslam!

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

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=141926&r1=141925&r2=141926&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Thu Oct 13 19:49:43 2011
@@ -162,6 +162,10 @@
   virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
   }
   
+  /// Defined - This hook is called whenever the 'defined' operator is seen.
+  virtual void Defined(const Token &MacroNameTok) {
+  }
+  
   /// SourceRangeSkipped - This hook is called when a source range is skipped.
   /// \param Range The SourceRange that was skipped. The range begins at the
   /// #if/#else directive and ends after the #endif/#else directive.
@@ -296,6 +300,11 @@
     Second->MacroUndefined(MacroNameTok, MI);
   }
 
+  virtual void Defined(const Token &MacroNameTok) {
+    First->Defined(MacroNameTok);
+    Second->Defined(MacroNameTok);
+  }
+
   virtual void SourceRangeSkipped(SourceRange Range) {
     First->SourceRangeSkipped(Range);
     Second->SourceRangeSkipped(Range);

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=141926&r1=141925&r2=141926&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Thu Oct 13 19:49:43 2011
@@ -117,6 +117,10 @@
     PP.markMacroAsUsed(Macro);
   }
 
+  // Invoke the 'defined' callback.
+  if (PPCallbacks *Callbacks = PP.getPPCallbacks())
+    Callbacks->Defined(PeekTok);
+
   // If we are in parens, ensure we have a trailing ).
   if (LParenLoc.isValid()) {
     // Consume identifier.





More information about the cfe-commits mailing list