]> granicus.if.org Git - clang/commitdiff
Add a preprocessor callback that is invoked every time the 'defined'
authorDouglas Gregor <dgregor@apple.com>
Fri, 14 Oct 2011 00:49:43 +0000 (00:49 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 14 Oct 2011 00:49:43 +0000 (00:49 +0000)
operator is seen, from Jason Haslam!

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

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

index 68684acbf752095c69c3d7f8fe458f9d79e85137..1fc1a05db646240f1c7b7c75a46ac99bc5057bab 100644 (file)
@@ -162,6 +162,10 @@ public:
   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 @@ public:
     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);
index 66a12eca0ffdf27c0af833bebee52ddb33320083..84156d59b9808019a39c262497223c0f26a00777 100644 (file)
@@ -117,6 +117,10 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
     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.