summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-10-14 00:49:43 +0000
committerDouglas Gregor <dgregor@apple.com>2011-10-14 00:49:43 +0000
commit3d5f955855cab5a831cc6b9339dc77a7d46f1a30 (patch)
tree1b50f01a9641fc4ab29ac2a80e06adb98798ae96
parent78f0ea710875425d501a4736565b3a34cf1840c8 (diff)
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
-rw-r--r--include/clang/Lex/PPCallbacks.h9
-rw-r--r--lib/Lex/PPExpressions.cpp4
2 files changed, 13 insertions, 0 deletions
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.