File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed
test/Interop/Cxx/ergonomics Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -3422,10 +3422,19 @@ namespace {
3422
3422
});
3423
3423
}
3424
3424
3425
+ static bool hasComputedPropertyAttr (const clang::Decl *decl) {
3426
+ return decl->hasAttrs () && llvm::any_of (decl->getAttrs (), [](auto *attr) {
3427
+ if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr))
3428
+ return swiftAttr->getAttribute () == " import_computed_property" ;
3429
+ return false ;
3430
+ });
3431
+ }
3432
+
3425
3433
Decl *VisitCXXMethodDecl (const clang::CXXMethodDecl *decl) {
3426
3434
auto method = VisitFunctionDecl (decl);
3427
3435
3428
- if (Impl.SwiftContext .LangOpts .CxxInteropGettersSettersAsProperties ) {
3436
+ if (Impl.SwiftContext .LangOpts .CxxInteropGettersSettersAsProperties ||
3437
+ hasComputedPropertyAttr (decl)) {
3429
3438
CXXMethodBridging bridgingInfo (decl);
3430
3439
if (bridgingInfo.classify () == CXXMethodBridging::Kind::getter) {
3431
3440
auto name = bridgingInfo.getClangName ().drop_front (3 );
Original file line number Diff line number Diff line change 31
31
#define CONFORMS_TO (_name ) \
32
32
__attribute__ ((swift_attr(_CXX_INTEROP_STRINGIFY(conforms_to:_name))))
33
33
34
+ #define SWIFT_COMPUTED_PROPERTY \
35
+ __attribute__ ((swift_attr(" import_computed_property" )))
36
+
37
+
34
38
#endif // SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H
Original file line number Diff line number Diff line change
1
+ // RUN: rm -rf %t
2
+ // RUN: split-file %s %t
3
+ // RUN: %target-swift-ide-test -print-module -module-to-print=Test -I %t/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
4
+
5
+ //--- Inputs/module.modulemap
6
+ module Test {
7
+ header " test.h "
8
+ requires cplusplus
9
+ }
10
+
11
+ //--- Inputs/test.h
12
+
13
+ #define SWIFT_COMPUTED_PROPERTY \
14
+ __attribute__( ( swift_attr ( " import_computed_property " ) ) )
15
+
16
+ struct Record {
17
+ int getX( ) SWIFT_COMPUTED_PROPERTY { return 42 ; }
18
+ } ;
19
+
20
+ //--- test.swift
21
+
22
+ // CHECK: struct Record {
23
+ // CHECK: init()
24
+ // CHECK: var x: Int32 { mutating get }
25
+ // CHECK: mutating func getX() -> Int32
26
+ // CHECK: }
You can’t perform that action at this time.
0 commit comments