Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed parameter forwarding for non-trivial types in C++ #2164

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi
${" | "..reactions.generateReactionViewForwardDeclarations()}
|
| class Inner: public lfutil::LFScope {
| const Inner& __lf_inner = *this;
| const Parameters __lf_parameters;
${" | "..parameters.generateInnerAliasDeclarations()}
${" | "..state.generateDeclarations()}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/org/lflang/generator/cpp/CppTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object CppTypes : TargetTypes {
}

override fun getTargetParamRef(expr: ParameterReference, type: InferredType?): String {
return "__lf_parameters.${expr.parameter.name}"
return "__lf_inner.${expr.parameter.name}"
}
}

Expand Down
23 changes: 14 additions & 9 deletions test/Cpp/src/ParameterHierarchy.lf
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@
*/
target Cpp

reactor Deep(p: int = 0) {
reactor Deep(p: int = 0, s: std::string = "foo") {
reaction(startup) {=
if(p != 42) {
reactor::log::Error() << "Parameter value is: " << p << ". Should have been 42.";
reactor::log::Error() << "Parameter value p is: " << p << ". Should have been 42.";
exit(1);
} else {
reactor::log::Info() << "Success.";
}
if(s != "bar") {
reactor::log::Error() << "Parameter value s is: " << s << ". Should have been bar.";
exit(2);
}

reactor::log::Info() << "Success.";
=}
}

reactor Intermediate(p: int = 10) {
a = new Deep(p=p)
reactor Intermediate(p: int = 10, s: std::string = "default") {
a = new Deep(p=p, s=s)
}

reactor Another(p: int = 20) {
a = new Intermediate(p = {= p =}) // also test forwarding parameters via target code blocks
reactor Another(p: int = 20, s: std::string = "default") {
// also test forwarding parameters via target code blocks
a = new Intermediate(p = {= p =}, s = {= s =})
}

main reactor ParameterHierarchy {
a = new Intermediate(p=42)
a = new Intermediate(p=42, s="bar")
}
Loading