diff options
-rw-r--r-- | include/clang/Lex/PPCallbacks.h | 10 | ||||
-rw-r--r-- | include/clang/Lex/PreprocessingRecord.h | 3 | ||||
-rw-r--r-- | lib/ARCMigrate/ARCMT.cpp | 3 | ||||
-rw-r--r-- | lib/Lex/PPMacroExpansion.cpp | 12 | ||||
-rw-r--r-- | lib/Lex/PreprocessingRecord.cpp | 5 | ||||
-rw-r--r-- | test/Index/c-index-getCursor-test.m | 2 | ||||
-rw-r--r-- | test/Index/nested-macro-instantiations.cpp | 4 |
7 files changed, 23 insertions, 16 deletions
diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index 27e96fe9e7..767bffa8fb 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -146,7 +146,8 @@ public: /// MacroExpands - This is called by /// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is /// found. - virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI) { + virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI, + SourceRange Range) { } /// MacroDefined - This hook is called whenever a macro definition is seen. @@ -269,9 +270,10 @@ public: Second->PragmaDiagnostic(Loc, Namespace, mapping, Str); } - virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI) { - First->MacroExpands(MacroNameTok, MI); - Second->MacroExpands(MacroNameTok, MI); + virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI, + SourceRange Range) { + First->MacroExpands(MacroNameTok, MI, Range); + Second->MacroExpands(MacroNameTok, MI, Range); } virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) { diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index b21e8e0374..7bcc962739 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -470,7 +470,8 @@ namespace clang { /// \c MacroInfo. MacroDefinition *findMacroDefinition(const MacroInfo *MI); - virtual void MacroExpands(const Token &Id, const MacroInfo* MI); + virtual void MacroExpands(const Token &Id, const MacroInfo* MI, + SourceRange Range); virtual void MacroDefined(const Token &Id, const MacroInfo *MI); virtual void MacroUndefined(const Token &Id, const MacroInfo *MI); virtual void InclusionDirective(SourceLocation HashLoc, diff --git a/lib/ARCMigrate/ARCMT.cpp b/lib/ARCMigrate/ARCMT.cpp index 260efae5bf..5779b4cbb9 100644 --- a/lib/ARCMigrate/ARCMT.cpp +++ b/lib/ARCMigrate/ARCMT.cpp @@ -399,7 +399,8 @@ public: ARCMTMacroTrackerPPCallbacks(std::vector<SourceLocation> &ARCMTMacroLocs) : ARCMTMacroLocs(ARCMTMacroLocs) { } - virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo *MI) { + virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo *MI, + SourceRange Range) { if (MacroNameTok.getIdentifierInfo()->getName() == getARCMTMacroName()) ARCMTMacroLocs.push_back(MacroNameTok.getLocation()); } diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index e966ebb62c..eaab73edc4 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -185,7 +185,8 @@ 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, MI); + if (Callbacks) Callbacks->MacroExpands(Identifier, MI, + Identifier.getLocation()); ExpandBuiltinMacro(Identifier); return false; } @@ -226,13 +227,14 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, // Notice that this macro has been used. markMacroAsUsed(MI); - if (Callbacks) Callbacks->MacroExpands(Identifier, MI); - - // If we started lexing a macro, enter the macro expansion body. - // Remember where the token is expanded. SourceLocation ExpandLoc = Identifier.getLocation(); + if (Callbacks) Callbacks->MacroExpands(Identifier, MI, + SourceRange(ExpandLoc, ExpansionEnd)); + + // If we started lexing a macro, enter the macro expansion body. + // If this macro expands to no tokens, don't bother to push it onto the // expansion stack, only to take it right back off. if (MI->getNumTokens() == 0) { diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp index 307c8aad2c..6303c3d629 100644 --- a/lib/Lex/PreprocessingRecord.cpp +++ b/lib/Lex/PreprocessingRecord.cpp @@ -108,14 +108,15 @@ MacroDefinition *PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) { return Pos->second; } -void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI) { +void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI, + SourceRange Range) { if (!IncludeNestedMacroExpansions && Id.getLocation().isMacroID()) return; if (MacroDefinition *Def = findMacroDefinition(MI)) PreprocessedEntities.push_back( new (*this) MacroExpansion(Id.getIdentifierInfo(), - Id.getLocation(), Def)); + Range, Def)); } void PreprocessingRecord::MacroDefined(const Token &Id, diff --git a/test/Index/c-index-getCursor-test.m b/test/Index/c-index-getCursor-test.m index 6df8c1abfe..9b1fec7493 100644 --- a/test/Index/c-index-getCursor-test.m +++ b/test/Index/c-index-getCursor-test.m @@ -165,4 +165,4 @@ void f() { // CHECK: [55:9 - 55:26] macro definition=CONCAT // CHECK: [57:1 - 57:10] FunctionDecl=f:57:6 (Definition) // CHECK: [58:4 - 58:8] VarDecl=my_var:58:8 (Definition) -// CHECK: [58:8 - 58:14] macro expansion=CONCAT:55:9 +// CHECK: [58:8 - 58:15] macro expansion=CONCAT:55:9 diff --git a/test/Index/nested-macro-instantiations.cpp b/test/Index/nested-macro-instantiations.cpp index 9d0c0521f4..0ed84dd008 100644 --- a/test/Index/nested-macro-instantiations.cpp +++ b/test/Index/nested-macro-instantiations.cpp @@ -7,7 +7,7 @@ WIBBLE(int x); // RUN: env CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_NESTED_MACROS=1 c-index-test -test-load-source-reparse 5 all %s | FileCheck -check-prefix CHECK-WITH-NESTED %s -// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:7] +// CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:14] // CHECK-WITH-NESTED: nested-macro-instantiations.cpp:3:19: macro expansion=BAR:2:9 Extent=[3:19 - 5:14] // CHECK-WITH-NESTED: nested-macro-instantiations.cpp:2:16: macro expansion=FOO:1:9 Extent=[2:16 - 5:14] // CHECK-WITH-NESTED: nested-macro-instantiations.cpp:5:1: VarDecl=x:5:1 (Definition) Extent=[5:1 - 5:14] @@ -15,6 +15,6 @@ WIBBLE(int x); // RUN: c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s // RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s // RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 all %s | FileCheck -check-prefix CHECK-WITHOUT-NESTED %s -// CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:7] +// CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: macro expansion=WIBBLE:3:9 Extent=[5:1 - 5:14] // CHECK-WITHOUT-NESTED-NOT: nested-macro-instantiations.cpp:3:19: macro expansion=BAR:2:9 Extent=[3:19 - 5:14] // CHECK-WITHOUT-NESTED: nested-macro-instantiations.cpp:5:1: VarDecl=x:5:1 (Definition) Extent=[5:1 - 5:14] |