Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix compilation error in code for reset state variables with time type #1964

Merged
merged 6 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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 {
Expand Down
45 changes: 45 additions & 0 deletions test/C/src/modal_models/ResetStateVariableOfTypeTime.lf
Original file line number Diff line number Diff line change
@@ -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);
=}
}
}
a-sr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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);
=}
}
}
a-sr marked this conversation as resolved.
Show resolved Hide resolved