Add SourceRange to PPCallbacks::Defined callback.

llvm-svn: 186707
This commit is contained in:
John Thompson 2013-07-19 18:50:04 +00:00
parent d54b12fcbc
commit cda95fe72c
4 changed files with 24 additions and 15 deletions

View File

@ -231,7 +231,8 @@ public:
/// \brief Hook called whenever the 'defined' operator is seen. /// \brief Hook called whenever the 'defined' operator is seen.
/// \param MD The MacroDirective if the name was a macro, null otherwise. /// \param MD The MacroDirective if the name was a macro, null otherwise.
virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD) { virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD,
SourceRange Range) {
} }
/// \brief Hook called when a source range is skipped. /// \brief Hook called when a source range is skipped.
@ -410,9 +411,10 @@ public:
Second->MacroUndefined(MacroNameTok, MD); Second->MacroUndefined(MacroNameTok, MD);
} }
virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD) { virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD,
First->Defined(MacroNameTok, MD); SourceRange Range) {
Second->Defined(MacroNameTok, MD); First->Defined(MacroNameTok, MD, Range);
Second->Defined(MacroNameTok, MD, Range);
} }
virtual void SourceRangeSkipped(SourceRange Range) { virtual void SourceRangeSkipped(SourceRange Range) {

View File

@ -576,7 +576,8 @@ namespace clang {
virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDirective *MD); const MacroDirective *MD);
/// \brief Hook called whenever the 'defined' operator is seen. /// \brief Hook called whenever the 'defined' operator is seen.
virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD); virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD,
SourceRange Range);
void addMacroExpansion(const Token &Id, const MacroInfo *MI, void addMacroExpansion(const Token &Id, const MacroInfo *MI,
SourceRange Range); SourceRange Range);

View File

@ -82,7 +82,8 @@ struct DefinedTracker {
static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT, static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
bool ValueLive, Preprocessor &PP) { bool ValueLive, Preprocessor &PP) {
IdentifierInfo *II; IdentifierInfo *II;
Result.setBegin(PeekTok.getLocation()); SourceLocation beginLoc(PeekTok.getLocation());
Result.setBegin(beginLoc);
// Get the next token, don't expand it. // Get the next token, don't expand it.
PP.LexUnexpandedNonComment(PeekTok); PP.LexUnexpandedNonComment(PeekTok);
@ -119,14 +120,8 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
PP.markMacroAsUsed(Macro->getMacroInfo()); PP.markMacroAsUsed(Macro->getMacroInfo());
} }
// Invoke the 'defined' callback. // Save macro token for callback.
if (PPCallbacks *Callbacks = PP.getPPCallbacks()) { Token macroToken(PeekTok);
MacroDirective *MD = Macro;
// Pass the MacroInfo for the macro name even if the value is dead.
if (!MD && Result.Val != 0)
MD = PP.getMacroDirective(II);
Callbacks->Defined(PeekTok, MD);
}
// If we are in parens, ensure we have a trailing ). // If we are in parens, ensure we have a trailing ).
if (LParenLoc.isValid()) { if (LParenLoc.isValid()) {
@ -148,6 +143,16 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
PP.LexNonComment(PeekTok); PP.LexNonComment(PeekTok);
} }
// Invoke the 'defined' callback.
if (PPCallbacks *Callbacks = PP.getPPCallbacks()) {
MacroDirective *MD = Macro;
// Pass the MacroInfo for the macro name even if the value is dead.
if (!MD && Result.Val != 0)
MD = PP.getMacroDirective(II);
Callbacks->Defined(macroToken, MD,
SourceRange(beginLoc, PeekTok.getLocation()));
}
// Success, remember that we saw defined(X). // Success, remember that we saw defined(X).
DT.State = DefinedTracker::DefinedMacro; DT.State = DefinedTracker::DefinedMacro;
DT.TheMacro = II; DT.TheMacro = II;

View File

@ -398,7 +398,8 @@ void PreprocessingRecord::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
} }
void PreprocessingRecord::Defined(const Token &MacroNameTok, void PreprocessingRecord::Defined(const Token &MacroNameTok,
const MacroDirective *MD) { const MacroDirective *MD,
SourceRange Range) {
// This is not actually a macro expansion but record it as a macro reference. // This is not actually a macro expansion but record it as a macro reference.
if (MD) if (MD)
addMacroExpansion(MacroNameTok, MD->getMacroInfo(), addMacroExpansion(MacroNameTok, MD->getMacroInfo(),