From 69aee1243f517cb1102e4041e2490f9429c45f81 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Tue, 14 May 2024 14:28:01 +0200 Subject: [PATCH] Fixed code generation for nested generic reactor instances --- .../generator/cpp/CppInstanceGenerator.kt | 2 +- test/Cpp/src/target/GenericComposition.lf | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/Cpp/src/target/GenericComposition.lf diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt index d734827252..32f6004f22 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppInstanceGenerator.kt @@ -103,7 +103,7 @@ class CppInstanceGenerator( // by iterating over the reactor parameters we make sure that the parameters are assigned in declaration order return reactor.parameters.mapNotNull { if (it.name in assignments) ".${it.name} = ${assignments[it.name]}" else null - }.joinToString(", ", "$reactorType::Parameters{", "}") + }.joinToString(", ", "typename $reactorType::Parameters{", "}") } private fun generateInitializer(inst: Instantiation): String? = with(inst) { diff --git a/test/Cpp/src/target/GenericComposition.lf b/test/Cpp/src/target/GenericComposition.lf new file mode 100644 index 0000000000..4c4083240a --- /dev/null +++ b/test/Cpp/src/target/GenericComposition.lf @@ -0,0 +1,33 @@ +target Cpp { + timeout: 1 sec +} + +reactor Counter { + state count: T(0) + timer t(0, 1 sec) + output out: T + + reaction(t) -> out {= + out.set(count); + count += 1; + =} +} + +reactor Printer { + input in: T + + reaction(in) {= + auto msg = *in.get(); + std::cout << msg << std::endl; + =} +} + +reactor MyWrapper { + c = new Counter() + p = new Printer() + c.out -> p.in +} + +main reactor { + m = new MyWrapper() +}