Skip to content

Commit 36d2533

Browse files
committed
[interop] NFC, refactor DeclAndTypePrinter::shouldInclude to its own function
1 parent ab202dc commit 36d2533

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "DeclAndTypePrinter.h"
1414
#include "ClangSyntaxPrinter.h"
15+
#include "ExposedDeclFilter.h"
1516
#include "PrimitiveTypeMapping.h"
1617
#include "PrintClangFunction.h"
1718
#include "PrintClangValueType.h"
@@ -2026,11 +2027,7 @@ auto DeclAndTypePrinter::getImpl() -> Implementation {
20262027
}
20272028

20282029
bool DeclAndTypePrinter::shouldInclude(const ValueDecl *VD) {
2029-
return !VD->isInvalid() &&
2030-
(outputLang == OutputLanguageMode::Cxx
2031-
? cxx_translation::isVisibleToCxx(VD, minRequiredAccess)
2032-
: isVisibleToObjC(VD, minRequiredAccess)) &&
2033-
!VD->getAttrs().hasAttribute<ImplementationOnlyAttr>();
2030+
return clang_translation::shouldExpose(VD, outputLang, minRequiredAccess);
20342031
}
20352032

20362033
void DeclAndTypePrinter::print(const Decl *D) {

lib/PrintAsClang/ExposedDeclFilter.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===--- ExposedDeclFilter.h - Controls which decls are exposed -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_PRINTASCLANG_EXPOSEDDECLFILTER_H
14+
#define SWIFT_PRINTASCLANG_EXPOSEDDECLFILTER_H
15+
16+
#include "OutputLanguageMode.h"
17+
#include "swift/AST/Decl.h"
18+
#include "swift/AST/SwiftNameTranslation.h"
19+
20+
namespace swift {
21+
22+
namespace clang_translation {
23+
24+
/// Returns true if the given declaration should be exposed in the generated
25+
/// Objective-C/C/C++ header, as depending on the specified output language.
26+
bool shouldExpose(const ValueDecl *VD, OutputLanguageMode outputLang,
27+
AccessLevel minRequiredAccess) {
28+
return !VD->isInvalid() &&
29+
(outputLang == OutputLanguageMode::Cxx
30+
? cxx_translation::isVisibleToCxx(VD, minRequiredAccess)
31+
: objc_translation::isVisibleToObjC(VD, minRequiredAccess)) &&
32+
!VD->getAttrs().hasAttribute<ImplementationOnlyAttr>();
33+
}
34+
35+
/// Returns true if the given declaration should be exposed in generated
36+
/// Objective-C/C/C++ header, regardless of what language the declaration is
37+
/// exposed to.
38+
bool shouldExpose(const ValueDecl *VD, AccessLevel minRequiredAccess) {
39+
return shouldExpose(VD, OutputLanguageMode::ObjC, minRequiredAccess) ||
40+
shouldExpose(VD, OutputLanguageMode::Cxx, minRequiredAccess);
41+
}
42+
43+
} // namespace clang_translation
44+
45+
} // end namespace swift
46+
47+
#endif

0 commit comments

Comments
 (0)