Skip to content

Commit 74d4ccb

Browse files
committed
Bring back ClangImporter::shouldIgnoreMacro()
1 parent 16deb28 commit 74d4ccb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ class ClangImporter final : public ClangModuleLoader {
231231
/// Otherwise, return nullptr.
232232
Decl *importDeclCached(const clang::NamedDecl *ClangDecl);
233233

234+
// Returns true if it is expected that the macro is ignored.
235+
bool shouldIgnoreMacro(StringRef Name, const clang::MacroInfo *Macro);
236+
234237
/// Returns the name of the given enum element as it would be imported into
235238
/// Swift.
236239
///

lib/ClangImporter/ClangImporter.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,8 +2055,7 @@ static bool shouldLowercaseValueName(StringRef name) {
20552055
}
20562056

20572057
/// Returns true if it is expected that the macro is ignored.
2058-
static bool shouldIgnoreMacro(const clang::IdentifierInfo *identifier,
2059-
const clang::MacroInfo *macro) {
2058+
static bool shouldIgnoreMacro(StringRef name, const clang::MacroInfo *macro) {
20602059
// Ignore include guards.
20612060
if (macro->isUsedForHeaderGuard())
20622061
return true;
@@ -2071,7 +2070,7 @@ static bool shouldIgnoreMacro(const clang::IdentifierInfo *identifier,
20712070

20722071
// Consult the blacklist of macros to suppress.
20732072
auto suppressMacro =
2074-
llvm::StringSwitch<bool>(identifier->getName())
2073+
llvm::StringSwitch<bool>(name)
20752074
#define SUPPRESS_MACRO(NAME) .Case(#NAME, true)
20762075
#include "MacroTable.def"
20772076
.Default(false);
@@ -2082,11 +2081,17 @@ static bool shouldIgnoreMacro(const clang::IdentifierInfo *identifier,
20822081
return false;
20832082
}
20842083

2084+
bool ClangImporter::shouldIgnoreMacro(StringRef Name,
2085+
const clang::MacroInfo *Macro) {
2086+
return ::shouldIgnoreMacro(Name, Macro);
2087+
}
2088+
20852089
Identifier ClangImporter::Implementation::importMacroName(
20862090
const clang::IdentifierInfo *clangIdentifier,
20872091
const clang::MacroInfo *macro) {
20882092
// If we're supposed to ignore this macro, return an empty identifier.
2089-
if (shouldIgnoreMacro(clangIdentifier, macro)) return Identifier();
2093+
if (::shouldIgnoreMacro(clangIdentifier->getName(), macro))
2094+
return Identifier();
20902095

20912096
// Import the identifier.
20922097
return importIdentifier(clangIdentifier);

0 commit comments

Comments
 (0)