From: Argyrios Kyrtzidis Date: Fri, 3 May 2013 22:31:32 +0000 (+0000) Subject: [Preprocessor] For the MacroExpands preprocessor callback, also pass the MacroArgs... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd08a0c178329ec16cb9e494e6880f3991708b93;p=clang [Preprocessor] For the MacroExpands preprocessor callback, also pass the MacroArgs object that provides information about the argument tokens for a function macro. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181065 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/MacroArgs.h b/include/clang/Lex/MacroArgs.h similarity index 100% rename from lib/Lex/MacroArgs.h rename to include/clang/Lex/MacroArgs.h diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index 45deb1756d..db2ecd247f 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -27,6 +27,7 @@ namespace clang { class Token; class IdentifierInfo; class MacroDirective; + class MacroArgs; /// \brief This interface provides a way to observe the actions of the /// preprocessor as it does its thing. @@ -206,7 +207,7 @@ public: /// \brief Called by Preprocessor::HandleMacroExpandedIdentifier when a /// macro invocation is found. virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, - SourceRange Range) { + SourceRange Range, const MacroArgs *Args) { } /// \brief Hook called whenever a macro definition is seen. @@ -376,9 +377,9 @@ public: } virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, - SourceRange Range) { - First->MacroExpands(MacroNameTok, MD, Range); - Second->MacroExpands(MacroNameTok, MD, Range); + SourceRange Range, const MacroArgs *Args) { + First->MacroExpands(MacroNameTok, MD, Range, Args); + Second->MacroExpands(MacroNameTok, MD, Range, Args); } virtual void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) { diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index b13b2be7f3..db74352aa8 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -559,7 +559,7 @@ namespace clang { private: virtual void MacroExpands(const Token &Id, const MacroDirective *MD, - SourceRange Range); + SourceRange Range, const MacroArgs *Args); virtual void MacroDefined(const Token &Id, const MacroDirective *MD); virtual void MacroUndefined(const Token &Id, const MacroDirective *MD); virtual void InclusionDirective(SourceLocation HashLoc, diff --git a/lib/ARCMigrate/ARCMT.cpp b/lib/ARCMigrate/ARCMT.cpp index 72f35205ca..fb452cdc73 100644 --- a/lib/ARCMigrate/ARCMT.cpp +++ b/lib/ARCMigrate/ARCMT.cpp @@ -482,7 +482,7 @@ public: : ARCMTMacroLocs(ARCMTMacroLocs) { } virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, - SourceRange Range) { + SourceRange Range, const MacroArgs *Args) { if (MacroNameTok.getIdentifierInfo()->getName() == getARCMTMacroName()) ARCMTMacroLocs.push_back(MacroNameTok.getLocation()); } diff --git a/lib/Lex/MacroArgs.cpp b/lib/Lex/MacroArgs.cpp index f6e781a936..d2dc04b36c 100644 --- a/lib/Lex/MacroArgs.cpp +++ b/lib/Lex/MacroArgs.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "MacroArgs.h" +#include "clang/Lex/MacroArgs.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index e5b00d6bb8..167823358a 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/Preprocessor.h" -#include "MacroArgs.h" +#include "clang/Lex/MacroArgs.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" @@ -223,7 +223,7 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, // If this is a builtin macro, like __LINE__ or _Pragma, handle it specially. if (MI->isBuiltinMacro()) { if (Callbacks) Callbacks->MacroExpands(Identifier, MD, - Identifier.getLocation()); + Identifier.getLocation(),/*Args=*/0); ExpandBuiltinMacro(Identifier); return false; } @@ -277,11 +277,12 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, DelayedMacroExpandsCallbacks.push_back( MacroExpandsInfo(Identifier, MD, ExpansionRange)); } else { - Callbacks->MacroExpands(Identifier, MD, ExpansionRange); + Callbacks->MacroExpands(Identifier, MD, ExpansionRange, Args); if (!DelayedMacroExpandsCallbacks.empty()) { for (unsigned i=0, e = DelayedMacroExpandsCallbacks.size(); i!=e; ++i) { MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i]; - Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range); + // FIXME: We lose macro args info with delayed callback. + Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range, /*Args=*/0); } DelayedMacroExpandsCallbacks.clear(); } diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp index b10e7f7bee..426b922562 100644 --- a/lib/Lex/PreprocessingRecord.cpp +++ b/lib/Lex/PreprocessingRecord.cpp @@ -406,7 +406,8 @@ void PreprocessingRecord::Defined(const Token &MacroNameTok, } void PreprocessingRecord::MacroExpands(const Token &Id,const MacroDirective *MD, - SourceRange Range) { + SourceRange Range, + const MacroArgs *Args) { addMacroExpansion(Id, MD->getMacroInfo(), Range); } diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 09f827991d..66f23f1018 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -26,7 +26,7 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/Preprocessor.h" -#include "MacroArgs.h" +#include "clang/Lex/MacroArgs.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp index 5b41fe9b8d..07753c7d7c 100644 --- a/lib/Lex/TokenLexer.cpp +++ b/lib/Lex/TokenLexer.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/TokenLexer.h" -#include "MacroArgs.h" +#include "clang/Lex/MacroArgs.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/MacroInfo.h" diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp index 2a504db2a4..27d8b8327f 100644 --- a/tools/libclang/Indexing.cpp +++ b/tools/libclang/Indexing.cpp @@ -292,7 +292,7 @@ public: /// MacroExpands - This is called by when a macro invocation is found. virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, - SourceRange Range) { + SourceRange Range, const MacroArgs *Args) { } /// SourceRangeSkipped - This hook is called when a source range is skipped. diff --git a/unittests/Basic/SourceManagerTest.cpp b/unittests/Basic/SourceManagerTest.cpp index 3f09cbb0f9..8e7f4a0371 100644 --- a/unittests/Basic/SourceManagerTest.cpp +++ b/unittests/Basic/SourceManagerTest.cpp @@ -257,7 +257,7 @@ public: true)); } virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, - SourceRange Range) { + SourceRange Range, const MacroArgs *Args) { Macros.push_back(MacroAction(MacroNameTok.getLocation(), MacroNameTok.getIdentifierInfo()->getName(), false));