[cfe-commits] r169665 - in /cfe/trunk: include/clang/Lex/PPCallbacks.h include/clang/Lex/PPConditionalDirectiveRecord.h lib/Lex/PPConditionalDirectiveRecord.cpp lib/Lex/PPDirectives.cpp lib/Lex/PPExpressions.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Dec 7 18:21:11 PST 2012
Author: akirtzidis
Date: Fri Dec 7 20:21:11 2012
New Revision: 169665
URL: http://llvm.org/viewvc/llvm-project?rev=169665&view=rev
Log:
[Preprocessor] Enhance Ifdef/Ifndef/Defined preprocessor callbacks to also pass
a MacroInfo object if the identifier was a macro name.
Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h
cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
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=169665&r1=169664&r2=169665&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Fri Dec 7 20:21:11 2012
@@ -199,7 +199,8 @@
}
/// \brief Hook called whenever the 'defined' operator is seen.
- virtual void Defined(const Token &MacroNameTok) {
+ /// \param MI The MacroInfo if the name was a macro, null otherwise.
+ virtual void Defined(const Token &MacroNameTok, const MacroInfo *MI) {
}
/// \brief Hook called when a source range is skipped.
@@ -228,13 +229,17 @@
/// \brief Hook called whenever an \#ifdef is seen.
/// \param Loc the source location of the directive.
/// \param MacroNameTok Information on the token being tested.
- virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok) {
+ /// \param MI The MacroInfo if the name was a macro, null otherwise.
+ virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
+ const MacroInfo *MI) {
}
/// \brief Hook called whenever an \#ifndef is seen.
/// \param Loc the source location of the directive.
/// \param MacroNameTok Information on the token being tested.
- virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok) {
+ /// \param MI The MacroInfo if the name was a macro, null otherwise.
+ virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
+ const MacroInfo *MI) {
}
/// \brief Hook called whenever an \#else is seen.
@@ -362,9 +367,9 @@
Second->MacroUndefined(MacroNameTok, MI);
}
- virtual void Defined(const Token &MacroNameTok) {
- First->Defined(MacroNameTok);
- Second->Defined(MacroNameTok);
+ virtual void Defined(const Token &MacroNameTok, const MacroInfo *MI) {
+ First->Defined(MacroNameTok, MI);
+ Second->Defined(MacroNameTok, MI);
}
virtual void SourceRangeSkipped(SourceRange Range) {
@@ -386,15 +391,17 @@
}
/// \brief Hook called whenever an \#ifdef is seen.
- virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok) {
- First->Ifdef(Loc, MacroNameTok);
- Second->Ifdef(Loc, MacroNameTok);
+ virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
+ const MacroInfo *MI) {
+ First->Ifdef(Loc, MacroNameTok, MI);
+ Second->Ifdef(Loc, MacroNameTok, MI);
}
/// \brief Hook called whenever an \#ifndef is seen.
- virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok) {
- First->Ifndef(Loc, MacroNameTok);
- Second->Ifndef(Loc, MacroNameTok);
+ virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
+ const MacroInfo *MI) {
+ First->Ifndef(Loc, MacroNameTok, MI);
+ Second->Ifndef(Loc, MacroNameTok, MI);
}
/// \brief Hook called whenever an \#else is seen.
Modified: cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h?rev=169665&r1=169664&r2=169665&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h Fri Dec 7 20:21:11 2012
@@ -89,8 +89,10 @@
virtual void If(SourceLocation Loc, SourceRange ConditionRange);
virtual void Elif(SourceLocation Loc, SourceRange ConditionRange,
SourceLocation IfLoc);
- virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok);
- virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok);
+ virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
+ const MacroInfo *MI);
+ virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
+ const MacroInfo *MI);
virtual void Else(SourceLocation Loc, SourceLocation IfLoc);
virtual void Endif(SourceLocation Loc, SourceLocation IfLoc);
};
Modified: cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp?rev=169665&r1=169664&r2=169665&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp Fri Dec 7 20:21:11 2012
@@ -82,13 +82,15 @@
}
void PPConditionalDirectiveRecord::Ifdef(SourceLocation Loc,
- const Token &MacroNameTok) {
+ const Token &MacroNameTok,
+ const MacroInfo *MI) {
addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
CondDirectiveStack.push_back(Loc);
}
void PPConditionalDirectiveRecord::Ifndef(SourceLocation Loc,
- const Token &MacroNameTok) {
+ const Token &MacroNameTok,
+ const MacroInfo *MI) {
addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
CondDirectiveStack.push_back(Loc);
}
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=169665&r1=169664&r2=169665&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Dec 7 20:21:11 2012
@@ -2047,9 +2047,9 @@
if (Callbacks) {
if (isIfndef)
- Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok);
+ Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok, MI);
else
- Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok);
+ Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MI);
}
// Should we include the stuff contained by this directive?
Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=169665&r1=169664&r2=169665&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Fri Dec 7 20:21:11 2012
@@ -111,15 +111,21 @@
Result.Val = II->hasMacroDefinition();
Result.Val.setIsUnsigned(false); // Result is signed intmax_t.
+ MacroInfo *Macro = 0;
// If there is a macro, mark it used.
if (Result.Val != 0 && ValueLive) {
- MacroInfo *Macro = PP.getMacroInfo(II);
+ Macro = PP.getMacroInfo(II);
PP.markMacroAsUsed(Macro);
}
// Invoke the 'defined' callback.
- if (PPCallbacks *Callbacks = PP.getPPCallbacks())
- Callbacks->Defined(PeekTok);
+ if (PPCallbacks *Callbacks = PP.getPPCallbacks()) {
+ MacroInfo *MI = Macro;
+ // Pass the MacroInfo for the macro name even if the value is dead.
+ if (!MI && Result.Val != 0)
+ MI = PP.getMacroInfo(II);
+ Callbacks->Defined(PeekTok, MI);
+ }
// If we are in parens, ensure we have a trailing ).
if (LParenLoc.isValid()) {
More information about the cfe-commits
mailing list