Skip to content

Commit

Permalink
Adds workaround for #419 and #605
Browse files Browse the repository at this point in the history
adds parantheses around the parameters in the code generator
  • Loading branch information
Rodario committed Nov 10, 2021
1 parent fca5fa8 commit 5eca37e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class CppParameterGenerator(private val reactor: Reactor) {
/** Get the default value of the receiver parameter in C++ code */
val Parameter.defaultValue: String
get() =
if (braces?.size == 2) "$targetType{${getInitializerList().joinToString(", ")}}"
else "$targetType(${getInitializerList().joinToString(", ")})"
if (braces?.size == 2) "($targetType){${getInitializerList().joinToString(", ")}}"
else "($targetType)(${getInitializerList().joinToString(", ")})"

/** Get a C++ type that is a const reference to the parameter type */
val Parameter.constRefType: String
Expand Down
15 changes: 15 additions & 0 deletions test/Cpp/src/target/PointerParameter.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
target Cpp;

reactor Foo(ptr: int*({=nullptr=})) {
reaction (startup) {=
std::cout << "Got " << *ptr << "\n";
=}
}

main reactor {
private preamble {=
int bar{42};
=}
// don't do this at home
foo = new Foo(ptr={=&bar=});
}

0 comments on commit 5eca37e

Please # to comment.