From 8baa059bebb9469e2f8d89bed77b3fa943806e5e Mon Sep 17 00:00:00 2001 From: Alexander Schulz-Rosengarten Date: Wed, 23 Aug 2023 18:22:27 +0200 Subject: [PATCH 1/4] Fixed compilation error in code for reset state variables with time type Fixes #1938 --- .../lflang/generator/c/CStateGenerator.java | 3 +- .../ResetStateVariableOfTypeTime.lf | 45 +++++++++++++++++++ ...esetStateVariableWithParameterizedValue.lf | 45 +++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 test/C/src/modal_models/ResetStateVariableOfTypeTime.lf create mode 100644 test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf diff --git a/core/src/main/java/org/lflang/generator/c/CStateGenerator.java b/core/src/main/java/org/lflang/generator/c/CStateGenerator.java index 225320bfe7..c8686173b6 100644 --- a/core/src/main/java/org/lflang/generator/c/CStateGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CStateGenerator.java @@ -88,8 +88,7 @@ private static String generateModalReset( + "]"; var type = types.getTargetType(instance.tpr.resolveType(ASTUtils.getInferredType(stateVar))); - if (ASTUtils.isOfTimeType(stateVar) - || ASTUtils.isParameterized(stateVar) && !stateVar.getInit().getExprs().isEmpty()) { + if (ASTUtils.isParameterized(stateVar) && !stateVar.getInit().getExprs().isEmpty()) { return CModesGenerator.generateStateResetStructure( instance, modeRef, selfRef, stateVar.getName(), initExpr, type); } else { diff --git a/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf new file mode 100644 index 0000000000..72e2075d2c --- /dev/null +++ b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf @@ -0,0 +1,45 @@ +/** + * Modal Reactor Test. + * Tests state variable with type time. + * https://github.com/lf-lang/lingua-franca/issues/1938 + * Model by Edward Lee. + */ +target C { + timeout: 3s, + fast: true +} + +reactor C { + input trigger:bool + reset state t:time = 0s + + reaction(trigger) {= + lf_print("t = %ld", self->t); + if (self->t != SEC(0)) { + lf_print("Error: Missing reset"); + } + + self->t = lf_time_logical(); + =} +} + +main reactor { + timer t(0, 1s) + + initial mode A { + c = new C() + + reaction(t) -> reset(B), c.trigger {= + lf_print("In A"); + lf_set(c.trigger, true); + lf_set_mode(B); + =} + } + + mode B { + reaction(t) -> reset(A) {= + lf_print("In B"); + lf_set_mode(A); + =} + } +} \ No newline at end of file diff --git a/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf new file mode 100644 index 0000000000..f7daaa8950 --- /dev/null +++ b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf @@ -0,0 +1,45 @@ +/** + * Modal Reactor Test. + * Tests state variable initialized via parameter. + * https://github.com/lf-lang/lingua-franca/issues/1938 + * Model by Edward Lee. + */ +target C { + timeout: 3s, + fast: true +} + +reactor C (init:int = 0) { + input trigger:bool + reset state i:int = init + + reaction(trigger) {= + lf_print("i = %d", self->i); + if (self->i != -1) { + lf_print("Error: Missing reset"); + } + + self->i += 10; + =} +} + +main reactor { + timer t(0, 1s) + + initial mode A { + c = new C(init = -1) + + reaction(t) -> reset(B), c.trigger {= + lf_print("In A"); + lf_set(c.trigger, true); + lf_set_mode(B); + =} + } + + mode B { + reaction(t) -> reset(A) {= + lf_print("In B"); + lf_set_mode(A); + =} + } +} \ No newline at end of file From abda76c8353aeb14300ea13c0bed52581cd10c9e Mon Sep 17 00:00:00 2001 From: Alexander Schulz-Rosengarten Date: Thu, 24 Aug 2023 09:29:16 +0200 Subject: [PATCH 2/4] Applied LF formatter --- .../ResetStateVariableOfTypeTime.lf | 27 +++++++--------- ...esetStateVariableWithParameterizedValue.lf | 31 +++++++++---------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf index 72e2075d2c..f7d25c97d6 100644 --- a/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf +++ b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf @@ -1,45 +1,42 @@ -/** - * Modal Reactor Test. - * Tests state variable with type time. +/** + * Modal Reactor Test. Tests state variable with type time. Model by Edward Lee. * https://github.com/lf-lang/lingua-franca/issues/1938 - * Model by Edward Lee. */ target C { - timeout: 3s, - fast: true + timeout: 3 s, + fast: true } reactor C { - input trigger:bool - reset state t:time = 0s - + input trigger: bool + reset state t: time = 0 s + reaction(trigger) {= lf_print("t = %ld", self->t); if (self->t != SEC(0)) { lf_print("Error: Missing reset"); } - + self->t = lf_time_logical(); =} } main reactor { - timer t(0, 1s) - + timer t(0, 1 s) + initial mode A { c = new C() - reaction(t) -> reset(B), c.trigger {= lf_print("In A"); lf_set(c.trigger, true); lf_set_mode(B); =} } - + mode B { reaction(t) -> reset(A) {= lf_print("In B"); lf_set_mode(A); =} } -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf index f7daaa8950..3e0096e5e0 100644 --- a/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf +++ b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf @@ -1,45 +1,42 @@ -/** - * Modal Reactor Test. - * Tests state variable initialized via parameter. +/** + * Modal Reactor Test. Tests state variable initialized via parameter. Model by Edward Lee. * https://github.com/lf-lang/lingua-franca/issues/1938 - * Model by Edward Lee. */ target C { - timeout: 3s, - fast: true + timeout: 3 s, + fast: true } -reactor C (init:int = 0) { - input trigger:bool - reset state i:int = init - +reactor C(init: int = 0) { + input trigger: bool + reset state i: int = init + reaction(trigger) {= lf_print("i = %d", self->i); if (self->i != -1) { lf_print("Error: Missing reset"); } - + self->i += 10; =} } main reactor { - timer t(0, 1s) - + timer t(0, 1 s) + initial mode A { - c = new C(init = -1) - + c = new C(init=-1) reaction(t) -> reset(B), c.trigger {= lf_print("In A"); lf_set(c.trigger, true); lf_set_mode(B); =} } - + mode B { reaction(t) -> reset(A) {= lf_print("In B"); lf_set_mode(A); =} } -} \ No newline at end of file +} From 7e7554e644e904f8208bb7ef2cc51effe45d1d9a Mon Sep 17 00:00:00 2001 From: Alexander Schulz-Rosengarten Date: Thu, 24 Aug 2023 09:31:33 +0200 Subject: [PATCH 3/4] Added newline --- test/C/src/modal_models/ResetStateVariableOfTypeTime.lf | 1 + .../src/modal_models/ResetStateVariableWithParameterizedValue.lf | 1 + 2 files changed, 2 insertions(+) diff --git a/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf index f7d25c97d6..0b5f40df23 100644 --- a/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf +++ b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf @@ -40,3 +40,4 @@ main reactor { =} } } + diff --git a/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf index 3e0096e5e0..e3081a4d0a 100644 --- a/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf +++ b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf @@ -40,3 +40,4 @@ main reactor { =} } } + From 9ec756ddae63de7b43c0444e929d8379183de5b0 Mon Sep 17 00:00:00 2001 From: Alexander Schulz-Rosengarten Date: Thu, 24 Aug 2023 11:09:30 +0200 Subject: [PATCH 4/4] Revert "Added newline" This reverts commit 7e7554e644e904f8208bb7ef2cc51effe45d1d9a. --- test/C/src/modal_models/ResetStateVariableOfTypeTime.lf | 1 - .../src/modal_models/ResetStateVariableWithParameterizedValue.lf | 1 - 2 files changed, 2 deletions(-) diff --git a/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf index 0b5f40df23..f7d25c97d6 100644 --- a/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf +++ b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf @@ -40,4 +40,3 @@ main reactor { =} } } - diff --git a/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf index e3081a4d0a..3e0096e5e0 100644 --- a/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf +++ b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf @@ -40,4 +40,3 @@ main reactor { =} } } -