Skip to content

Commit b89c0ea

Browse files
committed
Cleanup shouldExpose to avoid hardcoding access level, and update doc comment
1 parent 555b6e8 commit b89c0ea

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

include/swift/IRGen/SwiftIRDetailsProvider.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ class SILModule;
2525

2626
class IRDetailsProviderImpl;
2727

28-
/// An abstract interface provided to \c IRDetailsVisitor that provides access
29-
/// to the queries that can be performed on declarations to get their various
30-
/// ABI details.
28+
/// Provides access to the IRGen-based queries that can be performed on
29+
/// declarations to get their various ABI details.
3130
class IRDetailsProvider {
3231
public:
3332
IRDetailsProvider(const IRGenOptions &opts, SILModule &SILMod);

lib/PrintAsClang/ExposedDeclFilter.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515

1616
#include "OutputLanguageMode.h"
1717
#include "swift/AST/Decl.h"
18+
#include "swift/AST/Module.h"
1819
#include "swift/AST/SwiftNameTranslation.h"
1920

2021
namespace swift {
2122

2223
namespace clang_translation {
2324

25+
inline AccessLevel getRequiredAccess(const ModuleDecl &M) {
26+
return M.isExternallyConsumed() ? AccessLevel::Public : AccessLevel::Internal;
27+
}
28+
2429
/// Returns true if the given declaration should be exposed in the generated
2530
/// Objective-C/C/C++ header, as depending on the specified output language.
2631
inline bool shouldExpose(const ValueDecl *VD, OutputLanguageMode outputLang,
@@ -35,7 +40,8 @@ inline bool shouldExpose(const ValueDecl *VD, OutputLanguageMode outputLang,
3540
/// Returns true if the given declaration should be exposed in generated
3641
/// Objective-C/C/C++ header, regardless of what language the declaration is
3742
/// exposed to.
38-
inline bool shouldExpose(const ValueDecl *VD, AccessLevel minRequiredAccess) {
43+
inline bool shouldExpose(const ValueDecl *VD, const ModuleDecl &M) {
44+
auto minRequiredAccess = getRequiredAccess(M);
3945
return shouldExpose(VD, OutputLanguageMode::ObjC, minRequiredAccess) ||
4046
shouldExpose(VD, OutputLanguageMode::Cxx, minRequiredAccess);
4147
}

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "ClangSyntaxPrinter.h"
1616
#include "DeclAndTypePrinter.h"
17+
#include "ExposedDeclFilter.h"
1718
#include "OutputLanguageMode.h"
1819
#include "PrimitiveTypeMapping.h"
1920

@@ -635,15 +636,12 @@ class ModuleWriter {
635636
};
636637
} // end anonymous namespace
637638

638-
static AccessLevel getRequiredAccess(const ModuleDecl &M) {
639-
return M.isExternallyConsumed() ? AccessLevel::Public : AccessLevel::Internal;
640-
}
641-
642639
void swift::printModuleContentsAsObjC(
643640
raw_ostream &os, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
644641
ModuleDecl &M, SwiftToClangInteropContextImpl &interopContext) {
645642
llvm::raw_null_ostream prologueOS;
646-
ModuleWriter(os, prologueOS, imports, M, interopContext, getRequiredAccess(M),
643+
ModuleWriter(os, prologueOS, imports, M, interopContext,
644+
clang_translation::getRequiredAccess(M),
647645
OutputLanguageMode::ObjC)
648646
.write();
649647
}
@@ -657,7 +655,7 @@ void swift::printModuleContentsAsCxx(
657655
llvm::raw_string_ostream prologueOS{modulePrologueBuf};
658656

659657
ModuleWriter(moduleOS, prologueOS, imports, M, interopContext,
660-
getRequiredAccess(M), OutputLanguageMode::Cxx)
658+
clang_translation::getRequiredAccess(M), OutputLanguageMode::Cxx)
661659
.write();
662660

663661
// FIXME: refactor.

lib/PrintAsClang/SwiftToClangInteropContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void SwiftToClangInteropContext::collectSwiftIRGenDetails(
3939

4040
for (auto decl : decls) {
4141
const auto *VD = dyn_cast<ValueDecl>(decl);
42-
if (!VD || !clang_translation::shouldExpose(VD, AccessLevel::Public))
42+
if (!VD || !clang_translation::shouldExpose(VD, M))
4343
continue;
4444
if (const auto *SD = dyn_cast<StructDecl>(VD)) {
4545
if (auto typeInfo = irDetails.getTypeSizeAlignment(SD))

0 commit comments

Comments
 (0)