|
| 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