summaryrefslogtreecommitdiffstats
path: root/clang
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
commit82e0d728e8b8d2d80f6c8bf12afa69f53c2552a0 (patch)
tree84f19375e4a1ffe165a362317ac8442162d0072f /clang
parent01a678603a0d39a52eff956b5eb5a83ccb7a9fa3 (diff)
downloadbcm5719-llvm-82e0d728e8b8d2d80f6c8bf12afa69f53c2552a0.tar.gz
bcm5719-llvm-82e0d728e8b8d2d80f6c8bf12afa69f53c2552a0.zip
Add a preprocessor callback that is invoked every time the 'defined'
operator is seen, from Jason Haslam! llvm-svn: 141926
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Lex/PPCallbacks.h9
-rw-r--r--clang/lib/Lex/PPExpressions.cpp4
2 files changed, 13 insertions, 0 deletions
diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h
index 68684acbf75..1fc1a05db64 100644
--- a/clang/include/clang/Lex/PPCallbacks.h
+++ b/clang/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/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index 66a12eca0ff..84156d59b98 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/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.
OpenPOWER on IntegriCloud