diff --git a/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf b/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf index 2fe700e349..9d5b82d40e 100644 --- a/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf +++ b/cli/lfc/src/test/resources/org/lflang/cli/issue490.lf @@ -1,9 +1,9 @@ # https://github.com/lf-lang/lingua-franca/issues/490 # issue is that one error ends at EOF target Python; -main reactor R(p(3)) { - state liss(2, 3); +main reactor R(p = 3) { + state list = [2, 3]; reaction (startup) { - print(self.liss) + print(self.list) } } diff --git a/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr b/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr index da3437a551..f60c9516f2 100644 --- a/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr +++ b/cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr @@ -2,31 +2,31 @@ lfc: error: Name of main reactor must match the file name (or be omitted). --> %%%PATH.lf%%%:4:14 | 3 | target Python; -4 | main reactor R(p(3)) { +4 | main reactor R(p = 3) { | ^ Name of main reactor must match the file name (or be omitted). | -5 | state liss(2, 3); +5 | state list = [2, 3]; lfc: error: The Python target does not support reaction declarations. Please specify a reaction body. --> %%%PATH.lf%%%:6:3 | -5 | state liss(2, 3); +5 | state list = [2, 3]; 6 | reaction (startup) { | ^^^^^^^^^^^^^^^^^^^^ The Python target does not support reaction declarations. Please specify a reaction body. | -7 | print(self.liss) +7 | print(self.list) lfc: error: no viable alternative at input '{' --> %%%PATH.lf%%%:6:22 | -5 | state liss(2, 3); +5 | state list = [2, 3]; 6 | reaction (startup) { | ^ no viable alternative at input '{' | -7 | print(self.liss) +7 | print(self.list) lfc: error: no viable alternative at input '(' --> %%%PATH.lf%%%:7:5 | 6 | reaction (startup) { -7 | print(self.liss) +7 | print(self.list) | ^^^^^ no viable alternative at input '(' | 8 | } diff --git a/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf b/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf index 43705c8a51..ab8aecf3c1 100644 --- a/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf +++ b/cli/lfc/src/test/resources/org/lflang/cli/tabs.lf @@ -1,6 +1,6 @@ target C; main reactor { - state foo(1); - state bar(1); + state foo = 1; + state bar = 1; } diff --git a/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr b/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr index e3b1e765da..4ed692975b 100644 --- a/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr +++ b/cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr @@ -2,15 +2,15 @@ lfc: error: State must have a type. --> %%%PATH.lf%%%:4:2 | 3 | main reactor { -4 | state foo(1); - | ^^^^^^^^^^^^^ State must have a type. +4 | state foo = 1; + | ^^^^^^^^^^^^^^ State must have a type. | -5 | state bar(1); +5 | state bar = 1; lfc: error: State must have a type. --> %%%PATH.lf%%%:5:2 | -4 | state foo(1); -5 | state bar(1); - | ^^^^^^^^^^^^^^^^ State must have a type. +4 | state foo = 1; +5 | state bar = 1; + | ^^^^^^^^^^^^^^^^^ State must have a type. | 6 | } \ No newline at end of file diff --git a/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java b/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java index 6b66c7107e..863f6ac3ac 100644 --- a/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java +++ b/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java @@ -106,11 +106,11 @@ public class LffCliTest { List.of( """ target C - reactor Filter(period: int = 0, b: double[](0, 0)) {} + reactor Filter(period: int = 0, b: double[] = {0, 0}) {} main reactor { az_f = new Filter( period = 100, - b = (0.229019233988375, 0.421510777305010) + b = {0.229019233988375, 0.421510777305010} ) } """, @@ -128,9 +128,9 @@ reactor Filter(period: int = 0, b: double[] = {0, 0}) { """ target Rust reactor Snake { // q - state grid: SnakeGrid ({= /* foo */ SnakeGrid::new(grid_side, &snake) =}); // note that this one borrows snake temporarily - state grid2: SnakeGrid ({= // baz - SnakeGrid::new(grid_side, &snake) =}); + state grid: SnakeGrid = {= /* foo */ SnakeGrid::new(grid_side, &snake) =}; // note that this one borrows snake temporarily + state grid2: SnakeGrid = {= // baz + SnakeGrid::new(grid_side, &snake) =}; } """, """ diff --git a/core/src/main/java/org/lflang/generator/c/CTypes.java b/core/src/main/java/org/lflang/generator/c/CTypes.java index 8709b8e999..bd6d9127c3 100644 --- a/core/src/main/java/org/lflang/generator/c/CTypes.java +++ b/core/src/main/java/org/lflang/generator/c/CTypes.java @@ -66,11 +66,11 @@ public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull @Override public String getTargetTimeExpr(TimeValue time) { - if (time.unit != null) { - return cMacroName(time.unit) + "(" + time.getMagnitude() + ")"; - } else { - return Long.valueOf(time.getMagnitude()).toString(); - } + if (time.unit != null) { + return cMacroName(time.unit) + "(" + time.getMagnitude() + ")"; + } else { + return Long.valueOf(time.getMagnitude()).toString(); + } } /** diff --git a/core/src/main/java/org/lflang/validation/LFValidator.java b/core/src/main/java/org/lflang/validation/LFValidator.java index 06a96e25fe..b3260cdb02 100644 --- a/core/src/main/java/org/lflang/validation/LFValidator.java +++ b/core/src/main/java/org/lflang/validation/LFValidator.java @@ -177,7 +177,7 @@ public void checkBracedExpression(BracedListExpression expr) { if (!target.allowsBracedListExpressions()) { var message = "Braced expression lists are not a valid expression for the " + target + " target."; - error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); + error(message, Literals.BRACED_LIST_EXPRESSION__ITEMS); } } @@ -186,7 +186,7 @@ public void checkBracketExpression(BracketListExpression expr) { if (!target.allowsBracketListExpressions()) { var message = "Bracketed expression lists are not a valid expression for the " + target + " target."; - error(message, Literals.BRACKET_LIST_EXPRESSION.eContainmentFeature()); + error(message, Literals.BRACKET_LIST_EXPRESSION__ITEMS); } } @@ -194,10 +194,8 @@ public void checkBracketExpression(BracketListExpression expr) { public void checkParenthesisExpression(ParenthesisListExpression expr) { if (!target.allowsParenthesisListExpressions()) { var message = - "Parenthesis expression lists are not a valid expression for the " - + target - + " target."; - error(message, Literals.PARENTHESIS_LIST_EXPRESSION.eContainmentFeature()); + "Parenthesis expression lists are not a valid expression for the " + target + " target."; + error(message, Literals.PARENTHESIS_LIST_EXPRESSION__ITEMS); } } @@ -1086,7 +1084,8 @@ public void checkType(Type type) { error("Types are not allowed in the Python target", Literals.TYPE__ID); } - if (type.getCStyleArraySpec() != null && !List.of(Target.C, Target.CCPP, Target.TS).contains(target)) { + if (type.getCStyleArraySpec() != null + && !List.of(Target.C, Target.CCPP, Target.TS).contains(target)) { if (target == Target.CPP) { error( "C style array specifications are not allowed in this target. Please use std::array or" diff --git a/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java b/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java index 63b62951df..e65aa0548c 100644 --- a/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java +++ b/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java @@ -23,7 +23,7 @@ public void testSimple() { reactor Destination { input ok: bool input in: int - state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =}) + state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} } """); } @@ -34,34 +34,15 @@ public void testCodeExprEqItselfModuloIndent() { """ target C reactor Destination { - state s: tag_t({= + state s: tag_t = {= NEVER_TAG_INITIALIZER - =}) + =} } """, """ target C reactor Destination { - state s: tag_t({= NEVER_TAG_INITIALIZER =}) - } - """); - } - - @Test - public void testInitializerParensAreIrrelevantInAssignment() { - assertEquivalent( - """ - target C - reactor A(a: int(0)) {} - main reactor { - a = new A(a = 1) - } - """, - """ - target C - reactor A(a: int(0)) {} - main reactor { - a = new A(a = (1)) // mind the parens here. + state s: tag_t = {= NEVER_TAG_INITIALIZER =} } """); } diff --git a/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java b/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java index 4eeb089972..69dfe74e07 100644 --- a/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java +++ b/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java @@ -39,7 +39,7 @@ public void testAssignments() { reactor Destination { input ok: bool input in: int - state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =}) + state last_invoked: tag_t= {= NEVER_TAG_INITIALIZER =} } """, """ @@ -60,9 +60,9 @@ public void testState() { target Python reactor Destination { - state one_init: tag_t( {= NEVER_TAG_INITIALIZER =}) + state one_init: tag_t = {=NEVER_TAG_INITIALIZER=} state no_init: tag_t - state list_init(1,2) // this syntax is deprecated + state list_init = [1,2] // comment } """, """ @@ -71,7 +71,7 @@ state list_init(1,2) // this syntax is deprecated reactor Destination { state one_init: tag_t = {= NEVER_TAG_INITIALIZER =} state no_init: tag_t - state list_init(1, 2) # this syntax is deprecated + state list_init = [1, 2] # comment } """); } diff --git a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java index 61fcf74328..52a553e978 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import javax.inject.Inject; import org.eclipse.xtext.testing.InjectWith; @@ -95,13 +96,12 @@ public void uninitializedState() throws Exception { Model model = parser.parse( """ - target Cpp; + target C; main reactor Foo { state a; state b:int; state c:int[]; state d:time; - state e:time[]; } """); @@ -142,12 +142,12 @@ public void initialValue() throws Exception { parser.parse( """ target C; - reactor A(x:int(1)) {} - reactor B(y:int(2)) { + reactor A(x:int = 1) {} + reactor B(y:int = 2) { a1 = new A(x = y); a2 = new A(x = -1); } - reactor C(z:int(3)) { + reactor C(z:int = 3) { b1 = new B(y = z); b2 = new B(y = -2); } @@ -178,53 +178,52 @@ reactor C(z:int(3)) { model .eAllContents() .forEachRemaining( - (obj) -> { - if (obj instanceof Parameter) { - Parameter parameter = (Parameter) obj; - if (parameter.getName() == "x") { - var values = ASTUtils.initialValue(parameter, null); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "1"); - - values = ASTUtils.initialValue(parameter, List.of(map.get("a1"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "2"); - - values = ASTUtils.initialValue(parameter, List.of(map.get("a2"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1"); - - values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b1"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "3"); - - values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b1"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1"); - - values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b2"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-2"); - - values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b2"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1"); - } else if (parameter.getName() == "y") { - var values = ASTUtils.initialValue(parameter, null); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "2"); + obj -> { + if (obj instanceof Parameter parameter) { + if (Objects.equals(parameter.getName(), "x")) { + var value = ASTUtils.initialValue(parameter, null); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "1"); + + value = ASTUtils.initialValue(parameter, List.of(map.get("a1"))); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "2"); + + value = ASTUtils.initialValue(parameter, List.of(map.get("a2"))); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "-1"); + + value = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "3"); + + value = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "-1"); + + value = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "-2"); + + value = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "-1"); + } else if (Objects.equals(parameter.getName(), "y")) { + var value = ASTUtils.initialValue(parameter, null); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "2"); Assertions.assertThrows( IllegalArgumentException.class, () -> ASTUtils.initialValue(parameter, List.of(map.get("a1")))); - values = ASTUtils.initialValue(parameter, List.of(map.get("b1"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "3"); + value = ASTUtils.initialValue(parameter, List.of(map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "3"); - values = ASTUtils.initialValue(parameter, List.of(map.get("b2"))); - Assertions.assertInstanceOf(Literal.class, values.get(0)); - Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-2"); + value = ASTUtils.initialValue(parameter, List.of(map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, value); + Assertions.assertEquals(((Literal) value).getLiteral(), "-2"); } } }); diff --git a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index 577c02eb23..2ed0e60abe 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -820,7 +820,7 @@ public void parameterTypeMismatch() throws Exception { String testCase = """ target C; - main reactor (p:int(0)) { + main reactor (p:int = 0) { timer t(p, 1 sec); reaction(t) {= printf("Hello World.\\n"); @@ -878,7 +878,7 @@ public void overflowingParameterC() throws Exception { String testCase = """ target C; - main reactor(d:time(40 hours)) { + main reactor(d:time = 40 hours) { timer t; reaction(t) {= printf("Hello World.\\n"); @@ -1070,12 +1070,12 @@ public void stateAndParameterDeclarationsInC() throws Exception { String testCase = """ target C; - reactor Bar(a(0), // ERROR: type missing + reactor Bar(a = 0, // ERROR: type missing b:int, // ERROR: uninitialized t:time = 42, // ERROR: units missing x:int = 0, h:time = "bla", // ERROR: not a type - q:time(1 msec, 2 msec), // ERROR: not a list + q:time = {1 msec, 2 msec}, // ERROR: not a time y:int = t // ERROR: init using parameter ) { state offset:time = 42; // ERROR: units missing @@ -1093,8 +1093,7 @@ reactor Bar(a(0), // ERROR: type missing model, LfPackage.eINSTANCE.getParameter(), null, "Parameter must have a default value."); validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Missing time unit."); validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Invalid time value."); - validator.assertError( - model, LfPackage.eINSTANCE.getParameter(), null, "Expected exactly one time value."); + validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Invalid time value."); validator.assertError( model, LfPackage.eINSTANCE.getParameter(), @@ -1845,20 +1844,6 @@ public void testMissingStateType() throws Exception { "State must have a type."); } - @Test - public void testListWithParam() throws Exception { - String testCase = - """ - target C; - main reactor (A:int(1)) { state i:int(A, 2, 3) } - """; - validator.assertError( - parseWithoutError(testCase), - LfPackage.eINSTANCE.getStateVar(), - null, - "List items cannot refer to a parameter."); - } - @Test public void testCppMutableInput() throws Exception { String testCase =