Skip to content

Commit d3efca3

Browse files
authored
Merge pull request #65868 from hamishknight/macrowave
2 parents b116d35 + 1ffa8ee commit d3efca3

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,33 +3029,26 @@ bool ClangImporter::lookupDeclsFromHeader(StringRef Filename,
30293029
}
30303030

30313031
// Macros.
3032-
if (auto *ppRec = ClangPP.getPreprocessingRecord()) {
3033-
clang::SourceLocation B = ClangSM.getLocForStartOfFile(FID);
3034-
clang::SourceLocation E = ClangSM.getLocForEndOfFile(FID);
3035-
clang::SourceRange R(B, E);
3036-
const auto &Entities = ppRec->getPreprocessedEntitiesInRange(R);
3037-
for (auto I = Entities.begin(), E = Entities.end(); I != E; ++I) {
3038-
if (!ppRec->isEntityInFileID(I, FID))
3039-
continue;
3040-
clang::PreprocessedEntity *PPE = *I;
3041-
if (!PPE)
3042-
continue;
3043-
if (auto *MDR = dyn_cast<clang::MacroDefinitionRecord>(PPE)) {
3044-
auto *II = const_cast<clang::IdentifierInfo*>(MDR->getName());
3045-
auto MD = ClangPP.getMacroDefinition(II);
3046-
if (auto macroNode = getClangNodeForMacroDefinition(MD)) {
3047-
if (filter(macroNode)) {
3048-
auto MI = macroNode.getAsMacro();
3049-
Identifier Name = Impl.getNameImporter().importMacroName(II, MI);
3050-
if (Decl *imported = Impl.importMacro(Name, macroNode))
3051-
receiver(imported);
3052-
}
3053-
}
3054-
}
3055-
}
3032+
for (const auto &Iter : ClangPP.macros()) {
3033+
auto *II = Iter.first;
3034+
auto MD = ClangPP.getMacroDefinition(II);
3035+
MD.forAllDefinitions([&](clang::MacroInfo *Info) {
3036+
if (Info->isBuiltinMacro())
3037+
return;
3038+
3039+
auto Loc = Info->getDefinitionLoc();
3040+
if (Loc.isInvalid() || ClangSM.getFileID(Loc) != FID)
3041+
return;
30563042

3057-
// FIXME: Module imports inside that header.
3043+
ClangNode MacroNode = Info;
3044+
if (filter(MacroNode)) {
3045+
auto Name = Impl.getNameImporter().importMacroName(II, Info);
3046+
if (auto *Imported = Impl.importMacro(Name, MacroNode))
3047+
receiver(Imported);
3048+
}
3049+
});
30583050
}
3051+
// FIXME: Module imports inside that header.
30593052
return false;
30603053
}
30613054

test/IDE/Inputs/print_clang_header/header-to-print.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#undef MACRO_GOT_UNDEFINED
88
#define MY_MACRO 1
99

10+
#define MACRO_DUP 2
11+
#define MACRO_DUP 3
12+
1013
void doSomethingInHead(int arg);
1114

1215
@interface BaseInHead

test/IDE/Inputs/print_clang_header/header-to-print.h.command-line-include.printed.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Dispatch
44

55
var MY_MACRO: Int32 { get }
66

7+
var MACRO_DUP: Int32 { get }
8+
79
func doSomethingInHead(_ arg: Int32)
810

911
class BaseInHead {

test/IDE/Inputs/print_clang_header/header-to-print.h.module.printed.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
var MY_MACRO: Int32 { get }
33

4+
var MACRO_DUP: Int32 { get }
5+
46
func doSomethingInHead(_ arg: Int32)
57

68
class BaseInHead {

test/IDE/Inputs/print_clang_header/header-to-print.h.printed.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Dispatch
44

55
var MY_MACRO: Int32 { get }
66

7+
var MACRO_DUP: Int32 { get }
8+
79
func doSomethingInHead(_ arg: Int32)
810

911
class BaseInHead {

test/IDE/print_clang_header.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// FIXME: rdar://problem/19648117 Needs splitting objc parts out
22
// REQUIRES: objc_interop
33

4-
// REQUIRES: rdar102151774
5-
64
// RUN: echo '#include "header-to-print.h"' > %t.m
75
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -source-filename %s -print-header -header-to-print %S/Inputs/print_clang_header/header-to-print.h -print-regular-comments -enable-objc-interop -disable-objc-attr-requires-foundation-module --cc-args %target-cc-options -isysroot %clang-importer-sdk-path -fsyntax-only %t.m -I %S/Inputs/print_clang_header > %t.txt
86
// RUN: diff -u %S/Inputs/print_clang_header/header-to-print.h.printed.txt %t.txt
@@ -19,9 +17,6 @@
1917
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -source-filename %s -print-header -header-to-print %S/Inputs/print_clang_header/header-to-print.h -print-regular-comments -enable-objc-interop -disable-objc-attr-requires-foundation-module --cc-args %target-cc-options -isysroot %clang-importer-sdk-path -fsyntax-only %t.framework.m -F %t -ivfsoverlay %t.yaml -Xclang -fmodule-name=Foo > %t.framework.txt
2018
// RUN: diff -u %S/Inputs/print_clang_header/header-to-print.h.printed.txt %t.framework.txt
2119

22-
// Test header interface printing from a clang module, with the preprocessing record enabled before the CC args.
23-
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -source-filename %s -print-header -header-to-print %S/Inputs/print_clang_header/header-to-print.h -print-regular-comments -Xcc -Xclang -Xcc -detailed-preprocessing-record -enable-objc-interop -disable-objc-attr-requires-foundation-module --cc-args %target-cc-options -isysroot %clang-importer-sdk-path -fsyntax-only %t.framework.m -F %t -ivfsoverlay %t.yaml > %t.module.txt
20+
// Test header interface printing from a clang module.
21+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -source-filename %s -print-header -header-to-print %S/Inputs/print_clang_header/header-to-print.h -print-regular-comments -enable-objc-interop -disable-objc-attr-requires-foundation-module --cc-args %target-cc-options -isysroot %clang-importer-sdk-path -fsyntax-only %t.framework.m -F %t -ivfsoverlay %t.yaml > %t.module.txt
2422
// RUN: diff -u %S/Inputs/print_clang_header/header-to-print.h.module.printed.txt %t.module.txt
25-
// Test header interface printing from a clang module, with the preprocessing record enabled by the CC args.
26-
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -source-filename %s -print-header -header-to-print %S/Inputs/print_clang_header/header-to-print.h -print-regular-comments -enable-objc-interop -disable-objc-attr-requires-foundation-module --cc-args %target-cc-options -isysroot %clang-importer-sdk-path -fsyntax-only %t.framework.m -F %t -ivfsoverlay %t.yaml -Xclang -detailed-preprocessing-record > %t.module2.txt
27-
// RUN: diff -u %S/Inputs/print_clang_header/header-to-print.h.module.printed.txt %t.module2.txt

0 commit comments

Comments
 (0)