From: Douglas Gregor Date: Fri, 14 Oct 2011 00:49:43 +0000 (+0000) Subject: Add a preprocessor callback that is invoked every time the 'defined' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d5f955855cab5a831cc6b9339dc77a7d46f1a30;p=clang Add a preprocessor callback that is invoked every time the 'defined' operator is seen, from Jason Haslam! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141926 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index 68684acbf7..1fc1a05db6 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -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); diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp index 66a12eca0f..84156d59b9 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -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.