r186707 - Add SourceRange to PPCallbacks::Defined callback.
John Thompson
John.Thompson.JTSoftware at gmail.com
Fri Jul 19 11:50:04 PDT 2013
Author: jtsoftware
Date: Fri Jul 19 13:50:04 2013
New Revision: 186707
URL: http://llvm.org/viewvc/llvm-project?rev=186707&view=rev
Log:
Add SourceRange to PPCallbacks::Defined callback.
Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/include/clang/Lex/PreprocessingRecord.h
cfe/trunk/lib/Lex/PPExpressions.cpp
cfe/trunk/lib/Lex/PreprocessingRecord.cpp
Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=186707&r1=186706&r2=186707&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Fri Jul 19 13:50:04 2013
@@ -231,7 +231,8 @@ public:
/// \brief Hook called whenever the 'defined' operator is seen.
/// \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.
@@ -410,9 +411,10 @@ public:
Second->MacroUndefined(MacroNameTok, MD);
}
- virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD) {
- First->Defined(MacroNameTok, MD);
- Second->Defined(MacroNameTok, MD);
+ virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD,
+ SourceRange Range) {
+ First->Defined(MacroNameTok, MD, Range);
+ Second->Defined(MacroNameTok, MD, Range);
}
virtual void SourceRangeSkipped(SourceRange Range) {
Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=186707&r1=186706&r2=186707&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Fri Jul 19 13:50:04 2013
@@ -576,7 +576,8 @@ namespace clang {
virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDirective *MD);
/// \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,
SourceRange Range);
Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=186707&r1=186706&r2=186707&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Fri Jul 19 13:50:04 2013
@@ -82,7 +82,8 @@ struct DefinedTracker {
static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
bool ValueLive, Preprocessor &PP) {
IdentifierInfo *II;
- Result.setBegin(PeekTok.getLocation());
+ SourceLocation beginLoc(PeekTok.getLocation());
+ Result.setBegin(beginLoc);
// Get the next token, don't expand it.
PP.LexUnexpandedNonComment(PeekTok);
@@ -119,14 +120,8 @@ static bool EvaluateDefined(PPValue &Res
PP.markMacroAsUsed(Macro->getMacroInfo());
}
- // 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(PeekTok, MD);
- }
+ // Save macro token for callback.
+ Token macroToken(PeekTok);
// If we are in parens, ensure we have a trailing ).
if (LParenLoc.isValid()) {
@@ -148,6 +143,16 @@ static bool EvaluateDefined(PPValue &Res
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).
DT.State = DefinedTracker::DefinedMacro;
DT.TheMacro = II;
Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=186707&r1=186706&r2=186707&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Fri Jul 19 13:50:04 2013
@@ -398,7 +398,8 @@ void PreprocessingRecord::Ifndef(SourceL
}
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.
if (MD)
addMacroExpansion(MacroNameTok, MD->getMacroInfo(),
More information about the cfe-commits
mailing list