Skip to content

Commit ac7a536

Browse files
authored
Adds @cpp(noexcept) to attributes (#1509)
Signed-off-by: Yauheni Khnykin <yauheni.khnykin@here.com>
1 parent 9089357 commit ac7a536

9 files changed

Lines changed: 68 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Gluecodium project Release Notes
22

3+
4+
## Unreleased
5+
### Features:
6+
* `@Cpp(Noexcept)` works for properties in C++.
7+
38
## 13.5.4
49
### Features:
510
* Added support for `@Cpp(Noexcept)` attribute in C++.

docs/lime_attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ C++-specific attributes
140140
* \[**Name** **=**\] **"**_ElementName_**"**: marks an element to have a distinct name in C++.
141141
This is the default specification for this attribute.
142142
* **Const**: marks a function with a `const` qualifier in C++ generated code.
143-
* **Noexcept**: marks a function with a `noexcept` qualifier in C++ generated code. Can be applied to functions.
143+
* **Noexcept**: marks a function with a `noexcept` qualifier in C++ generated code. Can be applied to functions and properties.
144144
* **Accessors**: marks a struct to have accessor functions generated for fields and to generate
145145
struct fields as "private" in C++ generated code. Intended for use with `@Immutable` attribute.
146146
* **Ref**: marks a function or a property to return their value by const reference in C++

functional-tests/functional/input/lime/CppNoexceptMethods.lime

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ open class CppNoexceptClass {
2323

2424
@Cpp(Noexcept)
2525
fun getFoo(): String
26+
27+
@Cpp(Noexcept)
28+
property stringProperty: String
2629
}
2730

2831
class CppNoexceptClassInherited: CppNoexceptClass {
@@ -36,6 +39,9 @@ class CppNoexceptClassInherited: CppNoexceptClass {
3639
interface CppNoexceptInterface {
3740
@Cpp(Noexcept)
3841
fun getFoo(): String
42+
43+
@Cpp(Noexcept)
44+
property stringProperty: String
3945
}
4046

4147
interface CppNoexceptInterfaceInherited: CppNoexceptInterface {
@@ -52,4 +58,7 @@ class CppNoexceptInterfaceFactory {
5258

5359
@Cpp(Noexcept)
5460
static fun callGetFoo(callback: CppNoexceptInterface): String
61+
62+
@Cpp(Noexcept)
63+
static property stringProperty: String
5564
}

functional-tests/functional/input/src/cpp/CppNoexceptMethods.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ class CppNoexceptClassImpl final : public CppNoexceptClass {
3535
static_assert(noexcept(CppNoexceptClass::get_foo()));
3636
return "foo";
3737
}
38+
39+
::std::string get_string_property( ) const noexcept override {
40+
static_assert(noexcept(CppNoexceptClass::get_string_property()));
41+
return "foo";
42+
}
43+
void set_string_property( const ::std::string& )noexcept override {}
3844
};
3945

4046
class CppNoexceptClassInheritedImpl final : public CppNoexceptClassInherited {
@@ -48,6 +54,12 @@ class CppNoexceptClassInheritedImpl final : public CppNoexceptClassInherited {
4854
static_assert(noexcept(CppNoexceptClassInherited::get_bar()));
4955
return "bar";
5056
}
57+
58+
::std::string get_string_property( ) const noexcept override {
59+
static_assert(noexcept(CppNoexceptClassInherited::get_string_property()));
60+
return "foo";
61+
}
62+
void set_string_property( const ::std::string& )noexcept override {}
5163
};
5264

5365
class CppNoexceptInterfaceImpl final : public CppNoexceptInterface {
@@ -56,6 +68,12 @@ class CppNoexceptInterfaceImpl final : public CppNoexceptInterface {
5668
static_assert(noexcept(CppNoexceptInterface::get_foo()));
5769
return "foo";
5870
}
71+
72+
::std::string get_string_property( ) const noexcept override {
73+
static_assert(noexcept(CppNoexceptInterface::get_string_property()));
74+
return "foo";
75+
}
76+
void set_string_property( const ::std::string& )noexcept override {}
5977
};
6078

6179
class CppNoexceptInterfaceInheritedImpl final : public CppNoexceptInterfaceInherited {
@@ -69,6 +87,12 @@ class CppNoexceptInterfaceInheritedImpl final : public CppNoexceptInterfaceInher
6987
static_assert(noexcept(CppNoexceptInterfaceInherited::get_bar()));
7088
return "bar";
7189
}
90+
91+
::std::string get_string_property( ) const noexcept override {
92+
static_assert(noexcept(CppNoexceptInterfaceInherited::get_string_property()));
93+
return "foo";
94+
}
95+
void set_string_property( const ::std::string& )noexcept override {}
7296
};
7397
}
7498

@@ -97,4 +121,14 @@ CppNoexceptInterfaceFactory::call_get_foo(const std::shared_ptr<CppNoexceptInter
97121
return callback->get_foo();
98122
}
99123

124+
::std::string
125+
CppNoexceptInterfaceFactory::get_string_property() noexcept {
126+
return "foo";
127+
}
128+
129+
void
130+
CppNoexceptInterfaceFactory::set_string_property(const ::std::string&) noexcept {
131+
132+
}
133+
100134
}

gluecodium/src/main/resources/templates/cbridge/CBridgeCppProxy.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public:
5353
}
5454
{{/unless}}{{/each}}
5555
{{#each this.inheritedProperties this.properties}}{{#unless isStatic}}
56-
{{resolveName typeRef "C++"}} {{resolveName this "C++" "getter"}}() const override {
56+
{{resolveName typeRef "C++"}} {{resolveName this "C++" "getter"}}() const{{#if attributes.cpp.noexcept}} noexcept{{/if}} override {
5757
{{#unlessPredicate "shouldRetain"}}
5858
return {};
5959
{{/unlessPredicate}}{{#ifPredicate "shouldRetain"}}
@@ -62,7 +62,7 @@ public:
6262
{{/ifPredicate}}
6363
}
6464
{{#if setter}}
65-
void {{resolveName this "C++" "setter"}}({{#setter.parameters.0}}{{>cppParameter}}{{/setter.parameters.0}}) override {
65+
void {{resolveName this "C++" "setter"}}({{#setter.parameters.0}}{{>cppParameter}}{{/setter.parameters.0}}){{#if attributes.cpp.noexcept}} noexcept{{/if}} override {
6666
{{#ifPredicate setter "shouldRetain"}}
6767
mFunctions.{{resolveName setter}}({{!!
6868
}}mFunctions.swift_pointer, {{#setter.parameters.0}}{{>swiftParameter}}{{/setter.parameters.0}});

gluecodium/src/main/resources/templates/cpp/CppProperty.mustache

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
! License-Filename: LICENSE
1919
!
2020
!}}
21-
{{#set propertyElement=this cppRef=attributes.cpp.ref}}{{#getter}}
21+
{{#set propertyElement=this cppRef=attributes.cpp.ref cppNoexcept=attributes.cpp.noexcept}}{{#getter}}
2222
{{>cpp/CppFunctionDoc}}{{>cpp/CppAttributes}}
2323
{{#if isStatic}}static {{/if}}{{#unless isStatic}}virtual {{/unless}}{{!!
2424
}}{{#if cppRef}}const {{/if}}{{resolveName returnType.typeRef}}{{#if cppRef}}&{{/if}} {{!!
25-
}}{{resolveName propertyElement "" "getter"}}( ){{#unless isStatic}} const = 0{{/unless}};
25+
}}{{resolveName propertyElement "" "getter"}}( ){{#unless isStatic}} const{{/unless}}{{!!
26+
}}{{#if cppNoexcept}} noexcept{{/if}}{{#unless isStatic}} = 0{{/unless}};
2627
{{/getter}}
2728
{{#setter}}
2829
{{>cpp/CppFunctionDoc}}{{>cpp/CppAttributes}}
2930
{{#if isStatic}}static {{/if}}{{#unless isStatic}}virtual {{/unless}}void {{resolveName propertyElement "" "setter"}}{{!!
3031
}}( const {{#propertyElement}}{{resolveName typeRef}}{{#ifPredicate typeRef "needsRefSuffix"}}&{{/ifPredicate}}{{/propertyElement}} value ){{!!
31-
}}{{#unless isStatic}} = 0{{/unless}};
32+
}}{{#if cppNoexcept}} noexcept{{/if}}{{#unless isStatic}} = 0{{/unless}};
3233
{{/setter}}{{/set}}

gluecodium/src/main/resources/templates/ffi/FfiProxyDeclaration.mustache

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public:
101101
{{/unless}}{{/each}}
102102

103103
{{#each inheritedProperties properties}}{{#unless isStatic}}
104-
{{#getter}}
104+
{{#set hasNoexcept=attributes.cpp.noexcept}}{{#getter}}
105105
{{resolveName returnType.typeRef "C++"}}
106-
{{resolveName "C++"}}() const override {
106+
{{resolveName "C++"}}() const{{#if hasNoexcept}} noexcept{{/if}} override {
107107
{{#unlessPredicate "shouldRetain"}}
108108
return {};
109109
{{/unlessPredicate}}{{#ifPredicate "shouldRetain"}}
@@ -115,18 +115,19 @@ public:
115115
return _result;
116116
{{/ifPredicate}}
117117
}
118-
{{/getter}}
119-
{{#setter}}
118+
{{/getter}}{{/set}}
119+
120+
{{#set hasNoexcept=attributes.cpp.noexcept}}{{#setter}}
120121
void
121-
{{resolveName "C++"}}(const {{resolveName typeRef "C++ parameter"}} value) override {
122+
{{resolveName "C++"}}(const {{resolveName typeRef "C++ parameter"}} value){{#if hasNoexcept}} noexcept{{/if}} override {
122123
{{#ifPredicate "shouldRetain"}}
123124
dispatch([&]() { (*reinterpret_cast<bool (*)(Dart_Handle, {{resolveName typeRef}})>(p{{iter.position}}s))(
124125
Dart_HandleFromPersistent_DL(dart_persistent_handle),
125126
{{>ffi/FfiInternal}}::Conversion<{{resolveName typeRef "C++"}}>::toFfi(value)
126127
); });
127128
{{/ifPredicate}}
128129
}
129-
{{/setter}}
130+
{{/setter}}{{/set}}
130131
{{/unless}}{{/each}}
131132

132133
private:

gluecodium/src/main/resources/templates/jni/CppProxyHeader.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public:
7070
}}{{/proxyMethodHeader}}{{!!
7171
7272
}}{{+proxyPropertyHeader}}
73-
{{#set property=this}}{{#getter}}
74-
{{>cpp/CppReturnType}} {{resolveName property "C++" "getter"}}( ) const override;
73+
{{#set property=this cppNoexcept=attributes.cpp.noexcept}}{{#getter}}
74+
{{>cpp/CppReturnType}} {{resolveName property "C++" "getter"}}( ) const{{#if cppNoexcept}} noexcept{{/if}} override;
7575
{{/getter}}{{#setter}}
7676
void {{resolveName property "C++" "setter"}}( {{!!
77-
}}{{#parameters}}{{>jni/CppProxyMethodParameter}}{{/parameters}} ) override;
77+
}}{{#parameters}}{{>jni/CppProxyMethodParameter}}{{/parameters}} ){{#if cppNoexcept}} noexcept{{/if}} override;
7878
{{/setter}}{{/set}}
7979
{{/proxyPropertyHeader}}

gluecodium/src/main/resources/templates/jni/CppProxyImplementation.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace jni
6262
}}{{#unless cppName}}{{#instanceOf container "LimeLambda"}}operator(){{/instanceOf}}{{!!
6363
}}{{#notInstanceOf container "LimeLambda"}}{{resolveName "C++"}}{{/notInstanceOf}}{{/unless}}( {{!!
6464
}}{{joinPartial parameters "jni/CppProxyMethodParameter" ", "}} {{!!
65-
}}){{#if attributes.cpp.const isConst logic="or"}} const{{/if}}{{#if attributes.cpp.noexcept}} noexcept{{/if}} {
65+
}}){{#if attributes.cpp.const isConst logic="or"}} const{{/if}}{{#if attributes.cpp.noexcept cppNoexcept logic="or"}} noexcept{{/if}} {
6666
{{#unlessPredicate "shouldRetain"}}
6767
{{#unless returnType.isVoid}}return {};{{/unless}}
6868
{{/unlessPredicate}}{{#ifPredicate "shouldRetain"}}
@@ -129,12 +129,12 @@ namespace jni
129129
{{/proxyMethodImpl}}{{!!
130130
131131
}}{{+proxyPropertyImpl}}{{!!
132-
}}{{#if getter}}{{#set property=this function=getter isConst=true}}{{!!
132+
}}{{#if getter}}{{#set property=this function=getter isConst=true cppNoexcept=attributes.cpp.noexcept}}{{!!
133133
}}{{#resolveName property "C++" "getter"}}{{#set cppName=this}}{{!!
134134
}}{{#resolveName property "" "getter"}}{{#set javaName=this}}{{#function}}
135135
{{>proxyMethodImpl}}
136136
{{/function}}{{/set}}{{/resolveName}}{{/set}}{{/resolveName}}{{/set}}{{/if}}{{!!
137-
}}{{#if setter}}{{#set property=this function=setter}}{{!!
137+
}}{{#if setter}}{{#set property=this function=setter cppNoexcept=attributes.cpp.noexcept}}{{!!
138138
}}{{#resolveName property "C++" "setter"}}{{#set cppName=this}}{{!!
139139
}}{{#resolveName property "" "setter"}}{{#set javaName=this}}{{#function}}
140140
{{>proxyMethodImpl}}

0 commit comments

Comments
 (0)