mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #42511 from zoecarver/add-flag-import-as-computed-property
This commit is contained in:
@@ -281,6 +281,9 @@ namespace swift {
|
||||
/// disabled because it is not complete.
|
||||
bool EnableCXXInterop = false;
|
||||
|
||||
/// Imports getters and setters as computed properties.
|
||||
bool CxxInteropGettersSettersAsProperties = false;
|
||||
|
||||
/// On Darwin platforms, use the pre-stable ABI's mark bit for Swift
|
||||
/// classes instead of the stable ABI's bit. This is needed when
|
||||
/// targeting OSes prior to macOS 10.14.4 and iOS 12.2, where
|
||||
|
||||
@@ -836,6 +836,11 @@ def enable_cxx_interop :
|
||||
HelpText<"Alias for -enable-experimental-cxx-interop">,
|
||||
Flags<[FrontendOption, HelpHidden]>;
|
||||
|
||||
def cxx_interop_getters_setters_as_properties :
|
||||
Flag<["-"], "cxx-interop-getters-setters-as-properties">,
|
||||
HelpText<"Import getters and setters as computed properties in Swift">,
|
||||
Flags<[FrontendOption, HelpHidden]>;
|
||||
|
||||
def use_malloc : Flag<["-"], "use-malloc">,
|
||||
HelpText<"Allocate internal data structures using malloc "
|
||||
"(for memory debugging)">;
|
||||
|
||||
@@ -4480,6 +4480,7 @@ namespace {
|
||||
Decl *VisitCXXMethodDecl(const clang::CXXMethodDecl *decl) {
|
||||
auto method = VisitFunctionDecl(decl);
|
||||
|
||||
if (Impl.SwiftContext.LangOpts.CxxInteropGettersSettersAsProperties) {
|
||||
CXXMethodBridging bridgingInfo(decl);
|
||||
if (bridgingInfo.classify() == CXXMethodBridging::Kind::getter) {
|
||||
auto name = bridgingInfo.getClangName().drop_front(3);
|
||||
@@ -4488,6 +4489,7 @@ namespace {
|
||||
auto name = bridgingInfo.getClangName().drop_front(3);
|
||||
Impl.GetterSetterMap[name].second = static_cast<FuncDecl *>(method);
|
||||
}
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
@@ -807,6 +807,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
Args.hasFlag(OPT_enable_objc_interop, OPT_disable_objc_interop,
|
||||
Target.isOSDarwin());
|
||||
|
||||
Opts.CxxInteropGettersSettersAsProperties = Args.hasArg(OPT_cxx_interop_getters_setters_as_properties);
|
||||
|
||||
Opts.VerifyAllSubstitutionMaps |= Args.hasArg(OPT_verify_all_substitution_maps);
|
||||
|
||||
Opts.EnableVolatileModules |= Args.hasArg(OPT_enable_volatile_modules);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// RUN: %target-swift-ide-test -print-module -module-to-print=ImplicitComputedProperties -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
|
||||
// RUN: %target-swift-ide-test -print-module -module-to-print=ImplicitComputedProperties -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -cxx-interop-getters-setters-as-properties | %FileCheck %s
|
||||
|
||||
// CHECK: struct VoidGetter {
|
||||
// CHECK-NOT: var
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
|
||||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xfrontend -cxx-interop-getters-setters-as-properties)
|
||||
//
|
||||
// REQUIRES: executable_test
|
||||
//
|
||||
|
||||
@@ -766,6 +766,11 @@ static llvm::cl::opt<bool>
|
||||
llvm::cl::desc("Enable C++ interop."),
|
||||
llvm::cl::cat(Category), llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
CxxInteropGettersSettersAsProperties("cxx-interop-getters-setters-as-properties",
|
||||
llvm::cl::desc("Imports getters and setters as computed properties."),
|
||||
llvm::cl::cat(Category), llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
CanonicalizeType("canonicalize-type", llvm::cl::Hidden,
|
||||
llvm::cl::cat(Category), llvm::cl::init(false));
|
||||
@@ -4277,6 +4282,9 @@ int main(int argc, char *argv[]) {
|
||||
if (options::EnableCxxInterop) {
|
||||
InitInvok.getLangOptions().EnableCXXInterop = true;
|
||||
}
|
||||
if (options::CxxInteropGettersSettersAsProperties) {
|
||||
InitInvok.getLangOptions().CxxInteropGettersSettersAsProperties = true;
|
||||
}
|
||||
if (options::EnableExperimentalConcurrency) {
|
||||
InitInvok.getLangOptions().EnableExperimentalConcurrency = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user