From f2e20505f53b268e2b5006b374587373ed8d056f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Mon, 3 Jun 2024 14:53:20 -0700 Subject: [PATCH] Bumped the google-java-format version to 1.22.0 This updates the version of the google style that we use for formatting our code. Consequently, the formatting in some of our java files gets updated. --- cli/lfc/src/main/java/org/lflang/cli/Lfc.java | 1 + .../test/java/org/lflang/cli/LfcCliTest.java | 52 +- .../test/java/org/lflang/cli/LfdCliTest.java | 10 +- .../test/java/org/lflang/cli/LffCliTest.java | 196 +-- .../org/lflang/tests/lsp/ErrorInserter.java | 3 + .../java/org/lflang/tests/lsp/LspTests.java | 1 + .../main/java/org/lflang/InferredType.java | 1 + core/src/main/java/org/lflang/TimeValue.java | 1 + .../ast/DelayedConnectionTransformation.java | 1 + .../java/org/lflang/ast/FormattingUtil.java | 1 + .../synthesis/util/LayoutPostProcessing.java | 5 + .../federated/extensions/CExtension.java | 74 +- .../federated/extensions/CExtensionUtils.java | 36 +- .../federated/extensions/PythonExtension.java | 26 +- .../federated/extensions/TSExtension.java | 60 +- .../federated/generator/FedMainEmitter.java | 6 +- .../generator/FedPreambleEmitter.java | 14 +- .../FedROS2CPPSerialization.java | 26 +- .../java/org/lflang/generator/CodeMap.java | 2 + .../lflang/generator/GenerationException.java | 1 + .../HumanReadableReportingStrategy.java | 3 + .../LanguageServerMessageReporter.java | 1 + .../org/lflang/generator/MainContext.java | 1 + .../main/java/org/lflang/generator/Range.java | 1 + .../lflang/generator/ReactionInstance.java | 2 + .../lflang/generator/c/CCmakeGenerator.java | 16 +- .../org/lflang/generator/c/CGenerator.java | 24 +- .../generator/c/CMainFunctionGenerator.java | 1 + .../generator/c/CMixedRadixGenerator.java | 5 + .../generator/c/CPreambleGenerator.java | 1 + .../generator/c/CReactionGenerator.java | 1 + .../c/CReactorHeaderFileGenerator.java | 32 +- .../generator/c/TypeParameterizedReactor.java | 1 + .../generator/docker/CDockerGenerator.java | 20 +- .../docker/DockerComposeGenerator.java | 26 +- .../generator/docker/DockerGenerator.java | 4 +- .../docker/FedDockerComposeGenerator.java | 30 +- .../docker/PythonDockerGenerator.java | 12 +- .../generator/docker/TSDockerGenerator.java | 12 +- .../generator/python/PythonGenerator.java | 56 +- .../generator/python/PythonValidator.java | 2 + .../main/java/org/lflang/target/Target.java | 155 ++- .../property/ClockSyncOptionsProperty.java | 4 +- .../property/type/ClockSyncModeType.java | 1 + .../main/java/org/lflang/util/FileUtil.java | 1 + .../main/java/org/lflang/util/LFCommand.java | 1 + .../validation/ValidatorMessageReporter.java | 15 +- .../tests/compiler/EquivalenceUnitTests.java | 38 +- .../tests/compiler/FormattingUnitTests.java | 90 +- .../compiler/LinguaFrancaASTUtilsTest.java | 57 +- .../LinguaFrancaDependencyAnalysisTest.java | 22 +- .../compiler/LinguaFrancaParsingTest.java | 56 +- .../compiler/LinguaFrancaScopingTest.java | 58 +- .../compiler/LinguaFrancaValidationTest.java | 1209 +++++++++-------- .../java/org/lflang/tests/TestBase.java | 34 +- .../java/org/lflang/tests/TestRegistry.java | 1 + gradle.properties | 2 +- 57 files changed, 1284 insertions(+), 1228 deletions(-) diff --git a/cli/lfc/src/main/java/org/lflang/cli/Lfc.java b/cli/lfc/src/main/java/org/lflang/cli/Lfc.java index 0067723551..bed839942c 100644 --- a/cli/lfc/src/main/java/org/lflang/cli/Lfc.java +++ b/cli/lfc/src/main/java/org/lflang/cli/Lfc.java @@ -364,6 +364,7 @@ private Integer getWorkers() { } return workers; } + /** Check the values of the commandline arguments and return them. */ public GeneratorArguments getArgs() { diff --git a/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java b/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java index aa9090c480..6cf651f904 100644 --- a/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java +++ b/cli/lfc/src/test/java/org/lflang/cli/LfcCliTest.java @@ -66,35 +66,35 @@ public class LfcCliTest { static final String LF_PYTHON_FILE = """ - target Python - main reactor { - reaction(startup) {==} - } - """; + target Python + main reactor { + reaction(startup) {==} + } + """; static final String JSON_STRING = """ - { - "src": "src/File.lf", - "out": "src", - "properties": { - "build-type": "Release", - "clean": true, - "compiler": "gcc", - "external-runtime-path": "src", - "federated": true, - "logging": "info", - "lint": true, - "no-compile": true, - "print-statistics": true, - "quiet": true, - "rti": "path/to/rti", - "runtime-version": "rs", - "scheduler": "GEDF_NP", - "single-threaded": true - } - } - """; + { + "src": "src/File.lf", + "out": "src", + "properties": { + "build-type": "Release", + "clean": true, + "compiler": "gcc", + "external-runtime-path": "src", + "federated": true, + "logging": "info", + "lint": true, + "no-compile": true, + "print-statistics": true, + "quiet": true, + "rti": "path/to/rti", + "runtime-version": "rs", + "scheduler": "GEDF_NP", + "single-threaded": true + } + } + """; @Test public void testHelpArg() { diff --git a/cli/lfd/src/test/java/org/lflang/cli/LfdCliTest.java b/cli/lfd/src/test/java/org/lflang/cli/LfdCliTest.java index 4ab37245e6..1a8d54d495 100644 --- a/cli/lfd/src/test/java/org/lflang/cli/LfdCliTest.java +++ b/cli/lfd/src/test/java/org/lflang/cli/LfdCliTest.java @@ -46,11 +46,11 @@ public class LfdCliTest { private static final String VALID_FILE = """ - target Python - main reactor { - reaction(startup) {==} - } - """; + target Python + main reactor { + reaction(startup) {==} + } + """; LfdTestFixture lfdTester = new LfdTestFixture(); @Test 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 863f6ac3ac..b3115bf1f7 100644 --- a/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java +++ b/cli/lff/src/test/java/org/lflang/cli/LffCliTest.java @@ -45,133 +45,133 @@ public class LffCliTest { private static final String FILE_BEFORE_REFORMAT = """ - target Python; - main reactor { - reaction(startup) {= - =} - } - """; + target Python; + main reactor { + reaction(startup) {= + =} + } + """; private static final String FILE_AFTER_REFORMAT = """ - target Python + target Python - main reactor { - reaction(startup) {= =} - } - """; + main reactor { + reaction(startup) {= =} + } + """; private static final List> TEST_CASES = List.of( List.of( """ - target C - reactor Test { // this is a test - logical action a # this is an a - output humbug: int - reaction (a) -> /* moo */ humbug {= // this is a humbug reaction - /* it reacts like this*/ react react - =} - } - """, + target C + reactor Test { // this is a test + logical action a # this is an a + output humbug: int + reaction (a) -> /* moo */ humbug {= // this is a humbug reaction + /* it reacts like this*/ react react + =} + } + """, """ - target C - - // this is a test - reactor Test { - logical action a // this is an a - output humbug: int - - /** moo */ - // this is a humbug reaction - reaction(a) -> humbug {= - /* it reacts like this*/ react react - =} - } - """), + target C + + // this is a test + reactor Test { + logical action a // this is an a + output humbug: int + + /** moo */ + // this is a humbug reaction + reaction(a) -> humbug {= + /* it reacts like this*/ react react + =} + } + """), List.of( """ - target C - // Documentation - @icon("Variables.png") - reactor Variables {} - """, + target C + // Documentation + @icon("Variables.png") + reactor Variables {} + """, """ - target C + target C - // Documentation - @icon("Variables.png") - reactor Variables { - } - """), + // Documentation + @icon("Variables.png") + reactor Variables { + } + """), List.of( """ - target C - reactor Filter(period: int = 0, b: double[] = {0, 0}) {} - main reactor { - az_f = new Filter( - period = 100, - b = {0.229019233988375, 0.421510777305010} - ) - } - """, + target C + reactor Filter(period: int = 0, b: double[] = {0, 0}) {} + main reactor { + az_f = new Filter( + period = 100, + b = {0.229019233988375, 0.421510777305010} + ) + } + """, """ - target C + 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}) - } - """), + main reactor { + az_f = new Filter(period=100, b = {0.229019233988375, 0.421510777305010}) + } + """), List.of( """ - 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) =}; - } - """, +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) =}; +} +""", """ - target Rust - - // q - reactor Snake { - // note that this one borrows snake temporarily - state grid: SnakeGrid = {= /* foo */ SnakeGrid::new(grid_side, &snake) =} - // baz - state grid2: SnakeGrid = {= SnakeGrid::new(grid_side, &snake) =} - } - """), + target Rust + + // q + reactor Snake { + // note that this one borrows snake temporarily + state grid: SnakeGrid = {= /* foo */ SnakeGrid::new(grid_side, &snake) =} + // baz + state grid2: SnakeGrid = {= SnakeGrid::new(grid_side, &snake) =} + } + """), List.of( """ - target Cpp +target Cpp - reactor ContextManager { +reactor ContextManager { - \s - } + \s +} - reactor MACService { - mul_cm = new ContextManager() - } +reactor MACService { + mul_cm = new ContextManager() +} - """, +""", """ - target Cpp - - reactor ContextManager { - } - - reactor MACService { - mul_cm = new ContextManager< - loooooooooooooooooooooooooooooong, - looooooooooooooong, - loooooooooooooong>() - } - """)); + target Cpp + + reactor ContextManager { + } + + reactor MACService { + mul_cm = new ContextManager< + loooooooooooooooooooooooooooooong, + looooooooooooooong, + loooooooooooooong>() + } + """)); LffTestFixture lffTester = new LffTestFixture(); diff --git a/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java b/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java index 13b10156e2..d1695a5d67 100644 --- a/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java +++ b/core/src/integrationTest/java/org/lflang/tests/lsp/ErrorInserter.java @@ -76,10 +76,13 @@ private boolean get() { /** The zero-based indices of the touched lines. */ private final List badLines; + /** The original test on which this is based. */ private final Path srcFile; + /** The content of this test. */ private final LinkedList lines; + /** Whether the error inserter is permitted to insert a line before the current line. */ private final Predicate> insertCondition; diff --git a/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java b/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java index 842b8e4dfb..6ea5a3e6c4 100644 --- a/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java +++ b/core/src/integrationTest/java/org/lflang/tests/lsp/LspTests.java @@ -42,6 +42,7 @@ class LspTests extends LfInjectedTestBase { diagnosticsHaveKeyword("libprotoc") .or(diagnosticsHaveKeyword("protoc-c")) .or(diagnosticsIncludeText("could not be found")); + /** * The number of samples to take from each test category (with replacement) when doing validation * tests. diff --git a/core/src/main/java/org/lflang/InferredType.java b/core/src/main/java/org/lflang/InferredType.java index c05921a2ae..1830992cb0 100644 --- a/core/src/main/java/org/lflang/InferredType.java +++ b/core/src/main/java/org/lflang/InferredType.java @@ -49,6 +49,7 @@ public class InferredType { /** The AST node representing the inferred type if such a node exists. */ public final Type astType; + /** A flag indicating whether the inferred type has the base type time. */ public final boolean isTime; diff --git a/core/src/main/java/org/lflang/TimeValue.java b/core/src/main/java/org/lflang/TimeValue.java index 5e5b626816..f393544c5a 100644 --- a/core/src/main/java/org/lflang/TimeValue.java +++ b/core/src/main/java/org/lflang/TimeValue.java @@ -35,6 +35,7 @@ public final class TimeValue implements Comparable { /** The maximum value of this type. This is approximately equal to 292 years. */ public static final TimeValue MAX_VALUE = new TimeValue(Long.MAX_VALUE, TimeUnit.NANO); + /** A time value equal to zero. */ public static final TimeValue ZERO = new TimeValue(0, null); diff --git a/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java b/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java index b96fd524db..7a504d9aeb 100644 --- a/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java +++ b/core/src/main/java/org/lflang/ast/DelayedConnectionTransformation.java @@ -59,6 +59,7 @@ public class DelayedConnectionTransformation implements AstTransformation { private boolean transformAfterDelays = false; private boolean transformPhysicalConnection = false; + /** Collection of generated delay classes. */ private final LinkedHashSet delayClasses = new LinkedHashSet<>(); diff --git a/core/src/main/java/org/lflang/ast/FormattingUtil.java b/core/src/main/java/org/lflang/ast/FormattingUtil.java index f3ba6e585d..76222b41d6 100644 --- a/core/src/main/java/org/lflang/ast/FormattingUtil.java +++ b/core/src/main/java/org/lflang/ast/FormattingUtil.java @@ -126,6 +126,7 @@ static String lineWrapComments(List comments, int width, String singleLi ret.append(lineWrapComment(current.toString(), width, singleLineCommentPrefix)); return ret.toString(); } + /** Wrap lines. Do not merge lines that start with weird characters. */ private static String lineWrapComment(String comment, int width, String singleLineCommentPrefix) { var multiline = MULTILINE_COMMENT.matcher(comment).matches(); diff --git a/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java b/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java index 691ea42192..e635ffe0c1 100644 --- a/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java +++ b/core/src/main/java/org/lflang/diagram/synthesis/util/LayoutPostProcessing.java @@ -54,16 +54,21 @@ public class LayoutPostProcessing extends AbstractSynthesisExtensions { /** Synthesis option to control the order of nodes and edges by model order. */ public static final String MODEL_ORDER_OPTION = "Model Order"; + /** Uses semi-automatic layout. */ public static final String LEGACY = "Legacy"; + /** Only reactions are strictly ordered by their model order. */ public static final String STRICT_REACTION_ONLY = "Reactions Only"; + /** Reactions and reactor are strictly ordered by their model order. */ public static final String STRICT = "Reactions and Reactors"; + /** * Reactions and reactors are ordered by their model order if no additional crossing are created. */ public static final String TIE_BREAKER = "Optimize Crossings"; + /** * No crossing minimization is done at all. This requires that actions and timers are sorted based * on their model order. diff --git a/core/src/main/java/org/lflang/federated/extensions/CExtension.java b/core/src/main/java/org/lflang/federated/extensions/CExtension.java index 87a19e29d4..67ec873daa 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtension.java @@ -189,8 +189,8 @@ protected void deserialize( result.pr("lf_set(" + receiveRef + ", " + value + ");"); } } - case PROTO -> throw new UnsupportedOperationException( - "Protobuf serialization is not supported yet."); + case PROTO -> + throw new UnsupportedOperationException("Protobuf serialization is not supported yet."); case ROS2 -> { var portType = ASTUtils.getInferredType(((Port) receivingPort.getVariable())); var portTypeStr = types.getTargetType(portType); @@ -221,13 +221,13 @@ protected void deserialize( @Override public String outputInitializationBody() { return """ - extern reaction_t* port_absent_reaction[]; - void lf_enqueue_port_absent_reactions(environment_t*); - LF_PRINT_DEBUG("Adding network port absent reaction to table."); - port_absent_reaction[SENDERINDEXPARAMETER] = &self->_lf__reaction_2; - LF_PRINT_DEBUG("Added network output control reaction to table. Enqueueing it..."); - lf_enqueue_port_absent_reactions(self->base.environment); - """; + extern reaction_t* port_absent_reaction[]; + void lf_enqueue_port_absent_reactions(environment_t*); + LF_PRINT_DEBUG("Adding network port absent reaction to table."); + port_absent_reaction[SENDERINDEXPARAMETER] = &self->_lf__reaction_2; + LF_PRINT_DEBUG("Added network output control reaction to table. Enqueueing it..."); + lf_enqueue_port_absent_reactions(self->base.environment); + """; } @Override @@ -408,8 +408,8 @@ protected void serializeAndSend( result.pr(sendingFunction + "(" + commonArgs + ", " + pointerExpression + ");"); } } - case PROTO -> throw new UnsupportedOperationException( - "Protobuf serialization is not supported yet."); + case PROTO -> + throw new UnsupportedOperationException("Protobuf serialization is not supported yet."); case ROS2 -> { var typeStr = types.getTargetType(type); if (CUtil.isTokenType(type)) { @@ -511,10 +511,11 @@ public String generatePreamble( throws IOException { writePreambleFile(federate, fileConfig, rtiConfig, messageReporter); var includes = new CodeBuilder(); - includes.pr(""" - #ifdef __cplusplus - extern "C" { - #endif"""); + includes.pr( + """ + #ifdef __cplusplus + extern "C" { + #endif"""); includes.pr("#include \"core/federated/federate.h\""); includes.pr("#include \"core/federated/network/net_common.h\""); includes.pr("#include \"core/federated/network/net_util.h\""); @@ -522,10 +523,11 @@ public String generatePreamble( includes.pr("#include \"core/threaded/reactor_threaded.h\""); includes.pr("#include \"core/utils/util.h\""); includes.pr("extern federate_instance_t _fed;"); - includes.pr(""" - #ifdef __cplusplus - } - #endif"""); + includes.pr( + """ + #ifdef __cplusplus + } + #endif"""); includes.pr(generateSerializationIncludes(federate, fileConfig)); return includes.toString(); } @@ -578,9 +580,9 @@ protected String makePreamble( code.pr( CExtensionUtils.surroundWithIfFederatedDecentralized( """ - staa_t* staa_lst[%1$s]; - size_t staa_lst_size = %1$s; - """ + staa_t* staa_lst[%1$s]; + size_t staa_lst_size = %1$s; + """ .formatted(numOfSTAAOffsets))); code.pr(generateExecutablePreamble(federate, rtiConfig, messageReporter)); @@ -626,12 +628,12 @@ private String generateInitializeTriggers( federatedReactor.setName(oldFederatedReactorName); return """ - #define initialize_triggers_for_federate() \\ - do { \\ - %s - } \\ - while (0) - """ + #define initialize_triggers_for_federate() \\ + do { \\ + %s + } \\ + while (0) + """ .formatted((code.getCode().isBlank() ? "\\" : code.getCode()).indent(4).stripTrailing()); } @@ -644,10 +646,10 @@ private String generateExecutablePreamble( code.pr(generateCodeToInitializeFederate(federate, rtiConfig)); return """ - void _lf_executable_preamble(environment_t* env) { - %s - } - """ + void _lf_executable_preamble(environment_t* env) { + %s + } + """ .formatted(code.toString().indent(4).stripTrailing()); } @@ -658,10 +660,10 @@ private String generateSTAAInitialization(FederateInstance federate) { CExtensionUtils.surroundWithIfFederatedDecentralized(CExtensionUtils.stpStructs(federate))); return """ - void staa_initialization() { - %s - } - """ + void staa_initialization() { + %s + } + """ .formatted(code.toString().indent(4).stripTrailing()); } diff --git a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java index cf74cd2dae..6e905392c9 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -457,12 +457,12 @@ public static String surroundWithIfElseFederated(String insideIf, String insideE return surroundWithIfFederated(insideIf); } else { return """ - #ifdef FEDERATED - %s - #else - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #else + %s + #endif // FEDERATED + """ .formatted(insideIf, insideElse); } } @@ -473,10 +473,10 @@ public static String surroundWithIfElseFederated(String insideIf, String insideE */ public static String surroundWithIfFederated(String code) { return """ - #ifdef FEDERATED - %s - #endif // FEDERATED - """ + #ifdef FEDERATED + %s + #endif // FEDERATED + """ .formatted(code); } @@ -501,10 +501,10 @@ public static String surroundWithIfElseFederatedCentralized(String insideIf, Str */ public static String surroundWithIfFederatedCentralized(String code) { return """ - #ifdef FEDERATED_CENTRALIZED - %s - #endif // FEDERATED_CENTRALIZED - """ + #ifdef FEDERATED_CENTRALIZED + %s + #endif // FEDERATED_CENTRALIZED + """ .formatted(code); } @@ -514,10 +514,10 @@ public static String surroundWithIfFederatedCentralized(String code) { */ public static String surroundWithIfFederatedDecentralized(String code) { return """ - #ifdef FEDERATED_DECENTRALIZED - %s - #endif // FEDERATED_DECENTRALIZED - """ + #ifdef FEDERATED_DECENTRALIZED + %s + #endif // FEDERATED_DECENTRALIZED + """ .formatted(code); } diff --git a/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java b/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java index d6dc3ce44a..b387d4966c 100644 --- a/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/PythonExtension.java @@ -144,10 +144,10 @@ protected void deserialize( result.pr("lf_set_destructor(" + receiveRef + ", python_count_decrement);\n"); result.pr("lf_set_token(" + receiveRef + ", token);\n"); } - case PROTO -> throw new UnsupportedOperationException( - "Protobuf serialization is not supported yet."); - case ROS2 -> throw new UnsupportedOperationException( - "ROS2 serialization is not supported yet."); + case PROTO -> + throw new UnsupportedOperationException("Protobuf serialization is not supported yet."); + case ROS2 -> + throw new UnsupportedOperationException("ROS2 serialization is not supported yet."); } } @@ -174,10 +174,10 @@ protected void serializeAndSend( // Decrease the reference count for serialized_pyobject result.pr("Py_XDECREF(serialized_pyobject);\n"); } - case PROTO -> throw new UnsupportedOperationException( - "Protobuf serialization is not supported yet."); - case ROS2 -> throw new UnsupportedOperationException( - "ROS2 serialization is not supported yet."); + case PROTO -> + throw new UnsupportedOperationException("Protobuf serialization is not supported yet."); + case ROS2 -> + throw new UnsupportedOperationException("ROS2 serialization is not supported yet."); } } @@ -195,10 +195,10 @@ public String generatePreamble( throws IOException { writePreambleFile(federate, fileConfig, rtiConfig, messageReporter); return """ - import gc - import atexit - gc.disable() - atexit.register(os._exit, 0) - """; + import gc + import atexit + gc.disable() + atexit.register(os._exit, 0) + """; } } diff --git a/core/src/main/java/org/lflang/federated/extensions/TSExtension.java b/core/src/main/java/org/lflang/federated/extensions/TSExtension.java index 92ec170404..bdcb9ec6ac 100644 --- a/core/src/main/java/org/lflang/federated/extensions/TSExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/TSExtension.java @@ -49,11 +49,11 @@ public String generateNetworkReceiverBody( CoordinationMode coordinationMode, MessageReporter messageReporter) { return """ - // generateNetworkReceiverBody - if (%1$s !== undefined) { - %2$s%3$s = %1$s; - } - """ + // generateNetworkReceiverBody + if (%1$s !== undefined) { + %2$s%3$s = %1$s; + } + """ .formatted( action.getName(), receivingPort.getContainer() == null @@ -113,10 +113,10 @@ public String generateNetworkSenderBody( CoordinationMode coordinationMode, MessageReporter messageReporter) { return """ - if (%1$s%2$s[0] !== undefined) { - this.util.sendRTITimedMessage(%1$s%2$s[0], %3$s, %4$s, %5$s); - } - """ + if (%1$s%2$s[0] !== undefined) { + this.util.sendRTITimedMessage(%1$s%2$s[0], %3$s, %4$s, %5$s); + } + """ .formatted( sendingPort.getContainer() == null ? "" : sendingPort.getContainer().getName() + ".", sendingPort.getVariable().getName(), @@ -138,12 +138,12 @@ public String generatePortAbsentReactionBody( int receivingPortID = connection.getDstFederate().networkMessageActions.size(); var additionalDelayString = getNetworkDelayLiteral(connection.getDefinition().getDelay()); return """ - // If the output port has not been set for the current logical time, - // send an ABSENT message to the receiving federate - if (%1$s%2$s[0] === undefined) { - this.util.sendRTIPortAbsent(%3$d, %4$d, %5$s); - } - """ + // If the output port has not been set for the current logical time, + // send an ABSENT message to the receiving federate + if (%1$s%2$s[0] === undefined) { + this.util.sendRTIPortAbsent(%3$d, %4$d, %5$s); + } + """ .formatted( srcOutputPort.getContainer() == null ? "" @@ -168,21 +168,21 @@ public String generatePreamble( var minOutputDelay = getMinOutputDelay(federate, messageReporter); var upstreamConnectionDelays = getUpstreamConnectionDelays(federate); return """ - const defaultFederateConfig: __FederateConfig = { - dependsOn: [%s], - executionTimeout: undefined, - fast: false, - federateID: %d, - federationID: "Unidentified Federation", - keepAlive: true, - minOutputDelay: %s, - networkMessageActions: [%s], - rtiHost: "%s", - rtiPort: %d, - sendsTo: [%s], - upstreamConnectionDelays: [%s] - } - """ + const defaultFederateConfig: __FederateConfig = { + dependsOn: [%s], + executionTimeout: undefined, + fast: false, + federateID: %d, + federationID: "Unidentified Federation", + keepAlive: true, + minOutputDelay: %s, + networkMessageActions: [%s], + rtiHost: "%s", + rtiPort: %d, + sendsTo: [%s], + upstreamConnectionDelays: [%s] + } + """ .formatted( federate.dependsOn.keySet().stream() .map(e -> String.valueOf(e.id)) diff --git a/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java b/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java index 7dd1705ef5..78ed5b9727 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java +++ b/core/src/main/java/org/lflang/federated/generator/FedMainEmitter.java @@ -102,9 +102,9 @@ private CharSequence generateMainSignature( .collect(Collectors.joining(",", "(", ")")); return """ - @_fed_config() - main reactor %s { - """ + @_fed_config() + main reactor %s { + """ .formatted(paramList.equals("()") ? "" : paramList); } } diff --git a/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java b/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java index c74a605138..152d59d123 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java +++ b/core/src/main/java/org/lflang/federated/generator/FedPreambleEmitter.java @@ -33,19 +33,19 @@ String generatePreamble( for (Preamble p : mainModel.getPreambles()) { preambleCode.pr( """ - %spreamble {= - %s - =} - """ + %spreamble {= + %s + =} + """ .formatted( p.getVisibility() == null ? "" : p.getVisibility() + " ", toText(p.getCode()))); } preambleCode.pr( """ - preamble {= - %s - =}""" + preamble {= + %s + =}""" .formatted( FedTargetExtensionFactory.getExtension(federate.targetConfig.target) .generatePreamble(federate, fileConfig, rtiConfig, messageReporter))); diff --git a/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java b/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java index 8bbe25717a..4b00e7b272 100644 --- a/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java +++ b/core/src/main/java/org/lflang/federated/serialization/FedROS2CPPSerialization.java @@ -203,11 +203,11 @@ public StringBuilder generatePreambleForSupport() { preamble.append( """ - #include "rcutils/allocator.h" - #include "rclcpp/rclcpp.hpp" - #include "rclcpp/serialization.hpp" - #include "rclcpp/serialized_message.hpp" - """); + #include "rcutils/allocator.h" + #include "rclcpp/rclcpp.hpp" + #include "rclcpp/serialization.hpp" + #include "rclcpp/serialized_message.hpp" + """); return preamble; } @@ -222,16 +222,16 @@ public StringBuilder generateCompilerExtensionForSupport() { cMakeExtension.append( """ - enable_language(CXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings -O2") + enable_language(CXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings -O2") - find_package(ament_cmake REQUIRED) - find_package(rclcpp REQUIRED) - find_package(rclcpp_components REQUIRED) - find_package(rcutils) - find_package(rmw REQUIRED) + find_package(ament_cmake REQUIRED) + find_package(rclcpp REQUIRED) + find_package(rclcpp_components REQUIRED) + find_package(rcutils) + find_package(rmw REQUIRED) - ament_target_dependencies(${LF_MAIN_TARGET} PUBLIC rclcpp rmw)"""); + ament_target_dependencies(${LF_MAIN_TARGET} PUBLIC rclcpp rmw)"""); return cMakeExtension; } diff --git a/core/src/main/java/org/lflang/generator/CodeMap.java b/core/src/main/java/org/lflang/generator/CodeMap.java index 51e52acbf4..bd7c2cd9a0 100644 --- a/core/src/main/java/org/lflang/generator/CodeMap.java +++ b/core/src/main/java/org/lflang/generator/CodeMap.java @@ -181,11 +181,13 @@ private static int indexOf(String s, String imperfectSubstring) { /** The content of the generated file represented by this. */ private final String generatedCode; + /** * A mapping from Lingua Franca source paths to mappings from ranges in the generated file * represented by this to ranges in Lingua Franca files. */ private final Map> map; + /** * A mapping from Lingua Franca source paths to mappings from ranges in the generated file * represented by this to whether those ranges are copied verbatim from the source. diff --git a/core/src/main/java/org/lflang/generator/GenerationException.java b/core/src/main/java/org/lflang/generator/GenerationException.java index 1bc7985ee7..3c8390288b 100644 --- a/core/src/main/java/org/lflang/generator/GenerationException.java +++ b/core/src/main/java/org/lflang/generator/GenerationException.java @@ -25,6 +25,7 @@ package org.lflang.generator; import org.eclipse.emf.ecore.EObject; + // import org.jetbrains.annotations.Nullable; /** An exception that occurred during code generation. May also wrap another exception. */ diff --git a/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java b/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java index fedfcb6d36..7524960b87 100644 --- a/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java +++ b/core/src/main/java/org/lflang/generator/HumanReadableReportingStrategy.java @@ -18,10 +18,13 @@ public class HumanReadableReportingStrategy implements DiagnosticReporting.Strat /** A pattern that matches lines that should be reported via this strategy. */ private final Pattern diagnosticMessagePattern; + /** A pattern that matches labels that show the exact range to which the diagnostic pertains. */ private final Pattern labelPattern; + /** The path against which any paths should be resolved. */ private final Path relativeTo; + /** The next line to be processed, or {@code null}. */ private String bufferedLine; diff --git a/core/src/main/java/org/lflang/generator/LanguageServerMessageReporter.java b/core/src/main/java/org/lflang/generator/LanguageServerMessageReporter.java index a9fcff9f22..3145bdb2e4 100644 --- a/core/src/main/java/org/lflang/generator/LanguageServerMessageReporter.java +++ b/core/src/main/java/org/lflang/generator/LanguageServerMessageReporter.java @@ -33,6 +33,7 @@ public class LanguageServerMessageReporter extends MessageReporterBase { /** The document for which this is a diagnostic acceptor. */ private final EObject parseRoot; + /** The list of all diagnostics since the last reset. */ private final Map> diagnostics; diff --git a/core/src/main/java/org/lflang/generator/MainContext.java b/core/src/main/java/org/lflang/generator/MainContext.java index 294b9a61b0..f4b5386354 100644 --- a/core/src/main/java/org/lflang/generator/MainContext.java +++ b/core/src/main/java/org/lflang/generator/MainContext.java @@ -26,6 +26,7 @@ public class MainContext implements LFGeneratorContext { /** The indicator that shows whether this build process is canceled. */ private final CancelIndicator cancelIndicator; + /** The {@code ReportProgress} function of {@code this}. */ private final ReportProgress reportProgress; diff --git a/core/src/main/java/org/lflang/generator/Range.java b/core/src/main/java/org/lflang/generator/Range.java index 9300127d36..250a357326 100644 --- a/core/src/main/java/org/lflang/generator/Range.java +++ b/core/src/main/java/org/lflang/generator/Range.java @@ -17,6 +17,7 @@ public class Range implements Comparable { /** The start of the Range (INCLUSIVE). */ private final Position start; + /** The end of the Range (EXCLUSIVE). */ private final Position end; diff --git a/core/src/main/java/org/lflang/generator/ReactionInstance.java b/core/src/main/java/org/lflang/generator/ReactionInstance.java index 339a68be83..36b0aae54a 100644 --- a/core/src/main/java/org/lflang/generator/ReactionInstance.java +++ b/core/src/main/java/org/lflang/generator/ReactionInstance.java @@ -178,6 +178,7 @@ public ReactionInstance(Reaction definition, ReactorInstance parent, int index) /** The ports, actions, or timers that this reaction is triggered by or uses. */ public Set> sources = new LinkedHashSet<>(); + // FIXME: Above sources is misnamed because in the grammar, // "sources" are only the inputs a reaction reads without being // triggered by them. The name "reads" used here would be a better @@ -490,6 +491,7 @@ public class Runtime { // reaction (via a port), then the "dominating" field will // point to that upstream reaction. public Runtime dominating; + /** ID ranging from 0 to parent.getTotalWidth() - 1. */ public final int id; diff --git a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java index 4349b91dec..10b54138e8 100644 --- a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java @@ -59,11 +59,11 @@ public class CCmakeGenerator { private static final String DEFAULT_INSTALL_CODE = """ - install( - TARGETS ${LF_MAIN_TARGET} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ) - """; + install( + TARGETS ${LF_MAIN_TARGET} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + """; public static final String MIN_CMAKE_VERSION = "3.19"; @@ -435,9 +435,9 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("FIND_PATH( PROTOBUF_INCLUDE_DIR protobuf-c/protobuf-c.h)"); cMakeCode.pr( """ - find_library(PROTOBUF_LIBRARY\s - NAMES libprotobuf-c.a libprotobuf-c.so libprotobuf-c.dylib protobuf-c.lib protobuf-c.dll - )"""); + find_library(PROTOBUF_LIBRARY\s + NAMES libprotobuf-c.a libprotobuf-c.so libprotobuf-c.dylib protobuf-c.lib protobuf-c.dll + )"""); cMakeCode.pr( "find_package_handle_standard_args(libprotobuf-c DEFAULT_MSG PROTOBUF_INCLUDE_DIR" + " PROTOBUF_LIBRARY)"); diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index 0d47f7db74..298a637098 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -664,11 +664,11 @@ private void generateCodeFor(String lfModuleName) throws IOException { // from the federation and close any open sockets. code.pr( """ - #ifndef FEDERATED - void lf_terminate_execution(environment_t* env) { - (void) env; - } - #endif"""); + #ifndef FEDERATED + void lf_terminate_execution(environment_t* env) { + (void) env; + } + #endif"""); } } @@ -1100,13 +1100,13 @@ protected void generateAuxiliaryStructs( federatedExtension.pr( String.format( """ - #ifdef FEDERATED - #ifdef FEDERATED_DECENTRALIZED - %s intended_tag; - #endif - %s physical_time_of_arrival; - #endif - """, + #ifdef FEDERATED + #ifdef FEDERATED_DECENTRALIZED + %s intended_tag; + #endif + %s physical_time_of_arrival; + #endif + """, types.getTargetTagType(), types.getTargetTimeType())); for (Port p : allPorts(tpr.reactor())) { builder.pr( diff --git a/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java b/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java index ebd0c68682..53e3364cd0 100644 --- a/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CMainFunctionGenerator.java @@ -13,6 +13,7 @@ public class CMainFunctionGenerator { private TargetConfig targetConfig; + /** The command to run the generated code if specified in the target directive. */ private List runCommand; diff --git a/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java b/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java index f2bf71ef66..86190cd028 100644 --- a/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CMixedRadixGenerator.java @@ -3,14 +3,19 @@ public class CMixedRadixGenerator { /** Standardized name for channel index variable for a source. */ public static String sc = "src_channel"; + /** Standardized name for bank index variable for a source. */ public static String sb = "src_bank"; + /** Standardized name for runtime index variable for a source. */ public static String sr = "src_runtime"; + /** Standardized name for channel index variable for a destination. */ public static String dc = "dst_channel"; + /** Standardized name for bank index variable for a destination. */ public static String db = "dst_bank"; + /** Standardized name for runtime index variable for a destination. */ public static String dr = "dst_runtime"; } diff --git a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java index 53b35002f4..1b3a6d22d9 100644 --- a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java @@ -34,6 +34,7 @@ public static boolean arduinoBased(TargetConfig targetConfig) { return targetConfig.isSet(PlatformProperty.INSTANCE) && targetConfig.get(PlatformProperty.INSTANCE).platform() == Platform.ARDUINO; } + /** Add necessary source files specific to the target language. */ public static String generateIncludeStatements(TargetConfig targetConfig, boolean cppMode) { CodeBuilder code = new CodeBuilder(); diff --git a/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java b/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java index 87b5c6fcb9..151d2a47fb 100644 --- a/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CReactionGenerator.java @@ -39,6 +39,7 @@ public class CReactionGenerator { protected static String DISABLE_REACTION_INITIALIZATION_MARKER = "// **** Do not include initialization code in this reaction."; // FIXME: Such markers should + // not exist (#1687) /** diff --git a/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java b/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java index 5972789030..785db3a44c 100644 --- a/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CReactorHeaderFileGenerator.java @@ -87,15 +87,15 @@ private static void closeIncludeGuards(CodeBuilder builder) { private static void appendPoundIncludes(CodeBuilder builder) { builder.pr( """ - #ifdef __cplusplus - extern "C" { - #endif - #include "../include/api/schedule.h" - #include "../include/core/reactor.h" - #ifdef __cplusplus - } - #endif - """); + #ifdef __cplusplus + extern "C" { + #endif + #include "../include/api/schedule.h" + #include "../include/core/reactor.h" + #ifdef __cplusplus + } + #endif + """); } private static String userFacingSelfType(TypeParameterizedReactor tpr) { @@ -151,11 +151,11 @@ public static String nonInlineInitialization(Reaction r, TypeParameterizedReacto it.getType(false), it.getAlias(), it.getType(false), it.getRvalue()) : String.format( """ - %s %s[%s]; - for (int i = 0; i < %s; i++) { - %s[i] = (%s) self->_lf_%s[i].%s; - } - """, + %s %s[%s]; + for (int i = 0; i < %s; i++) { + %s[i] = (%s) self->_lf_%s[i].%s; + } + """, it.getType(true).replaceFirst("\\*", ""), it.getAlias(), CReactionGenerator.maxContainedReactorBankWidth( @@ -229,20 +229,24 @@ String getType(boolean userFacing) { .orElseThrow()); return typeName + "*" + (getWidth() != null ? "*" : "") + (isMultiport ? "*" : ""); } + /** The name of the variable as it appears in the LF source. */ String getName() { return tv.getName(); } + /** The alias of the variable that should be used in code generation. */ String getAlias() { return getName(); // TODO: avoid naming conflicts } + /** The width of the container, if applicable. */ String getWidth() { return container == null || container.getWidthSpec() == null ? null : "self->_lf_" + r.getName() + "_width"; } + /** The representation of this port as used by the LF programmer. */ String getRvalue() { return container == null ? getName() : container.getName() + "." + getName(); diff --git a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java index 07191ebcac..e5f3b1e811 100644 --- a/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java +++ b/core/src/main/java/org/lflang/generator/c/TypeParameterizedReactor.java @@ -16,6 +16,7 @@ public class TypeParameterizedReactor { /** The syntactic reactor class definition. */ private final Reactor reactor; + /** The type arguments associated with this particular variant of the reactor class. */ private final Map typeArgs; diff --git a/core/src/main/java/org/lflang/generator/docker/CDockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/CDockerGenerator.java index 3292485c57..41f459776c 100644 --- a/core/src/main/java/org/lflang/generator/docker/CDockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/CDockerGenerator.java @@ -70,19 +70,19 @@ protected String generateRunForBuildDependencies() { var compiler = config.target == Target.CCPP ? "g++" : "gcc"; if (baseImage().equals(defaultImage())) { return """ - # Install build dependencies - RUN set -ex && apk add --no-cache %s musl-dev cmake make - # Optional user specified run command - %s - """ + # Install build dependencies + RUN set -ex && apk add --no-cache %s musl-dev cmake make + # Optional user specified run command + %s + """ .formatted(compiler, userRunCommand()); } else { return """ - # Optional user specified run command - %s - # Check for build dependencies - RUN which make && which cmake && which %s - """ + # Optional user specified run command + %s + # Check for build dependencies + RUN which make && which cmake && which %s + """ .formatted(userRunCommand(), compiler); } } diff --git a/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java b/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java index 0b2addacdc..9b6f684f75 100644 --- a/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java @@ -32,10 +32,10 @@ public DockerComposeGenerator(LFGeneratorContext context) { */ protected String generateDockerNetwork(String networkName) { return """ - networks: - default: - name: "%s" - """ + networks: + default: + name: "%s" + """ .formatted(networkName); } @@ -46,10 +46,10 @@ protected String generateDockerNetwork(String networkName) { */ protected String generateDockerServices(List services) { return """ - version: "3.9" - services: - %s - """ + version: "3.9" + services: + %s + """ .formatted( services.stream().map(this::getServiceDescription).collect(Collectors.joining("\n"))); } @@ -57,11 +57,11 @@ protected String generateDockerServices(List services) { /** Turn given docker data into a string. */ protected String getServiceDescription(DockerData data) { return """ - %s: - build: - context: "%s" - container_name: "%s" - """ + %s: + build: + context: "%s" + container_name: "%s" + """ .formatted(getServiceName(data), getBuildContext(data), getContainerName(data)); } diff --git a/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java index 2fc47e9f0e..a9a7b71d52 100644 --- a/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/DockerGenerator.java @@ -78,8 +78,8 @@ public static DockerGenerator dockerGeneratorFactory(LFGeneratorContext context) case C, CCPP -> new CDockerGenerator(context); case TS -> new TSDockerGenerator(context); case Python -> new PythonDockerGenerator(context); - case CPP, Rust -> throw new IllegalArgumentException( - "No Docker support for " + target + " yet."); + case CPP, Rust -> + throw new IllegalArgumentException("No Docker support for " + target + " yet."); }; } } diff --git a/core/src/main/java/org/lflang/generator/docker/FedDockerComposeGenerator.java b/core/src/main/java/org/lflang/generator/docker/FedDockerComposeGenerator.java index 346b58556b..1e5deb3860 100644 --- a/core/src/main/java/org/lflang/generator/docker/FedDockerComposeGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/FedDockerComposeGenerator.java @@ -44,19 +44,19 @@ protected String generateDockerServices(List services) { .formatted(this.rtiImage, this.rtiHost, tracing, services.size(), containerName); if (this.rtiImage.equals(DockerOptions.LOCAL_RTI_IMAGE)) { return """ - %s\ - rti: - build: - context: "rti" - %s - """ + %s\ + rti: + build: + context: "rti" + %s + """ .formatted(super.generateDockerServices(services), attributes); } else { return """ - %s\ - rti: - %s - """ + %s\ + rti: + %s + """ .formatted(super.generateDockerServices(services), attributes); } } @@ -64,11 +64,11 @@ protected String generateDockerServices(List services) { @Override protected String getServiceDescription(DockerData data) { return """ - %s\ - command: "-i 1" - depends_on: - - rti - """ + %s\ + command: "-i 1" + depends_on: + - rti + """ .formatted(super.getServiceDescription(data)); } diff --git a/core/src/main/java/org/lflang/generator/docker/PythonDockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/PythonDockerGenerator.java index 4b68c36cdd..371c880771 100644 --- a/core/src/main/java/org/lflang/generator/docker/PythonDockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/PythonDockerGenerator.java @@ -23,14 +23,14 @@ public String defaultImage() { protected String generateRunForBuildDependencies() { if (baseImage().equals(defaultImage())) { return """ - # Install build dependencies - RUN set -ex && apt-get update && apt-get install -y python3-pip && pip install cmake - """; + # Install build dependencies + RUN set -ex && apt-get update && apt-get install -y python3-pip && pip install cmake + """; } else { return """ - # Check for build dependencies - RUN which make && which cmake && which gcc - """; + # Check for build dependencies + RUN which make && which cmake && which gcc + """; } } diff --git a/core/src/main/java/org/lflang/generator/docker/TSDockerGenerator.java b/core/src/main/java/org/lflang/generator/docker/TSDockerGenerator.java index e22d9a3e86..5fae515778 100644 --- a/core/src/main/java/org/lflang/generator/docker/TSDockerGenerator.java +++ b/core/src/main/java/org/lflang/generator/docker/TSDockerGenerator.java @@ -17,12 +17,12 @@ public TSDockerGenerator(LFGeneratorContext context) { /** Return the content of the docker file for [tsFileName]. */ public String generateDockerFileContent() { return """ - FROM %s - WORKDIR /linguafranca/$name - %s - COPY . . - ENTRYPOINT ["node", "dist/%s.js"] - """ + FROM %s + WORKDIR /linguafranca/$name + %s + COPY . . + ENTRYPOINT ["node", "dist/%s.js"] + """ .formatted(baseImage(), generateRunForBuildDependencies(), context.getFileConfig().name); } diff --git a/core/src/main/java/org/lflang/generator/python/PythonGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonGenerator.java index 6d27e4f142..758dbaa36f 100644 --- a/core/src/main/java/org/lflang/generator/python/PythonGenerator.java +++ b/core/src/main/java/org/lflang/generator/python/PythonGenerator.java @@ -571,19 +571,19 @@ private static String setUpMainTarget( """ + cSources.collect(Collectors.joining("\n ", " ", "\n")) + """ - ) - if (MSVC) - set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) - set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}) - set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}) - set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_SOURCE_DIR}) - set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_SOURCE_DIR}) - endif (MSVC) - set_target_properties(${LF_MAIN_TARGET} PROPERTIES PREFIX "") - include_directories(${Python_INCLUDE_DIRS}) - target_link_libraries(${LF_MAIN_TARGET} PRIVATE ${Python_LIBRARIES}) - target_compile_definitions(${LF_MAIN_TARGET} PUBLIC MODULE_NAME=) - """) +) +if (MSVC) + set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) + set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}) + set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}) + set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_SOURCE_DIR}) + set_target_properties(${LF_MAIN_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_SOURCE_DIR}) +endif (MSVC) +set_target_properties(${LF_MAIN_TARGET} PROPERTIES PREFIX "") +include_directories(${Python_INCLUDE_DIRS}) +target_link_libraries(${LF_MAIN_TARGET} PRIVATE ${Python_LIBRARIES}) +target_compile_definitions(${LF_MAIN_TARGET} PUBLIC MODULE_NAME=) +""") .replace("", generatePythonModuleName(executableName)); // The use of fileConfig.name will break federated execution, but that's fine } @@ -594,21 +594,21 @@ private static String generateCmakeInstall(FileConfig fileConfig) { // need to replace '\' with '\\' on Windwos for proper escaping in cmake final var pyMainName = pyMainPath.toString().replace("\\", "\\\\"); return """ - if(WIN32) - file(GENERATE OUTPUT .bat CONTENT - "@echo off - \ - ${Python_EXECUTABLE} %*" - ) - install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/.bat DESTINATION ${CMAKE_INSTALL_BINDIR}) - else() - file(GENERATE OUTPUT CONTENT - "#!/bin/sh\\n\\ - ${Python_EXECUTABLE} \\"$@\\"" - ) - install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/ DESTINATION ${CMAKE_INSTALL_BINDIR}) - endif() - """ + if(WIN32) + file(GENERATE OUTPUT .bat CONTENT + "@echo off +\ + ${Python_EXECUTABLE} %*" + ) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/.bat DESTINATION ${CMAKE_INSTALL_BINDIR}) + else() + file(GENERATE OUTPUT CONTENT + "#!/bin/sh\\n\\ + ${Python_EXECUTABLE} \\"$@\\"" + ) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/ DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() +""" .replace("", fileConfig.name) .replace("", pyMainName); } diff --git a/core/src/main/java/org/lflang/generator/python/PythonValidator.java b/core/src/main/java/org/lflang/generator/python/PythonValidator.java index 8dedb2f9d6..6f550440f9 100644 --- a/core/src/main/java/org/lflang/generator/python/PythonValidator.java +++ b/core/src/main/java/org/lflang/generator/python/PythonValidator.java @@ -35,10 +35,12 @@ public class PythonValidator extends org.lflang.generator.Validator { /** The pattern that diagnostics from the Python compiler typically follow. */ private static final Pattern DIAGNOSTIC_MESSAGE_PATTERN = Pattern.compile("(\\*\\*\\*)?\\s*File \"(?.*?\\.py)\", line (?\\d+)"); + /** * The pattern typically followed by the message that typically follows the main diagnostic line. */ private static final Pattern MESSAGE = Pattern.compile("\\w*Error: .*"); + /** An alternative pattern that at least some diagnostics from the Python compiler may follow. */ private static final Pattern ALT_DIAGNOSTIC_MESSAGE_PATTERN = Pattern.compile(".*Error:.*line (?\\d+)\\)"); diff --git a/core/src/main/java/org/lflang/target/Target.java b/core/src/main/java/org/lflang/target/Target.java index 811220be53..6467023621 100644 --- a/core/src/main/java/org/lflang/target/Target.java +++ b/core/src/main/java/org/lflang/target/Target.java @@ -589,81 +589,86 @@ public static Target fromDecl(TargetDecl targetDecl) { public void initialize(TargetConfig config) { switch (this) { - case C, CCPP -> config.register( - AuthProperty.INSTANCE, - BuildCommandsProperty.INSTANCE, - BuildTypeProperty.INSTANCE, - ClockSyncModeProperty.INSTANCE, - ClockSyncOptionsProperty.INSTANCE, - CmakeIncludeProperty.INSTANCE, - CompileDefinitionsProperty.INSTANCE, - CompilerProperty.INSTANCE, - CoordinationOptionsProperty.INSTANCE, - CoordinationProperty.INSTANCE, - DockerProperty.INSTANCE, - FilesProperty.INSTANCE, - KeepaliveProperty.INSTANCE, - NoSourceMappingProperty.INSTANCE, - PlatformProperty.INSTANCE, - ProtobufsProperty.INSTANCE, - SchedulerProperty.INSTANCE, - SingleThreadedProperty.INSTANCE, - TracingProperty.INSTANCE, - TracePluginProperty.INSTANCE, - VerifyProperty.INSTANCE, - WorkersProperty.INSTANCE); - case CPP -> config.register( - BuildTypeProperty.INSTANCE, - CmakeIncludeProperty.INSTANCE, - CompilerProperty.INSTANCE, - ExportDependencyGraphProperty.INSTANCE, - ExportToYamlProperty.INSTANCE, - ExternalRuntimePathProperty.INSTANCE, - NoRuntimeValidationProperty.INSTANCE, - PrintStatisticsProperty.INSTANCE, - Ros2DependenciesProperty.INSTANCE, - Ros2Property.INSTANCE, - RuntimeVersionProperty.INSTANCE, - TracingProperty.INSTANCE, - WorkersProperty.INSTANCE); - case Python -> config.register( - AuthProperty.INSTANCE, - BuildCommandsProperty.INSTANCE, - BuildTypeProperty.INSTANCE, - ClockSyncModeProperty.INSTANCE, - ClockSyncOptionsProperty.INSTANCE, - CompileDefinitionsProperty.INSTANCE, - CoordinationOptionsProperty.INSTANCE, - CoordinationProperty.INSTANCE, - DockerProperty.INSTANCE, - FilesProperty.INSTANCE, - KeepaliveProperty.INSTANCE, - NoSourceMappingProperty.INSTANCE, - ProtobufsProperty.INSTANCE, - SchedulerProperty.INSTANCE, - SingleThreadedProperty.INSTANCE, - TracingProperty.INSTANCE, - TracePluginProperty.INSTANCE, - WorkersProperty.INSTANCE); - case Rust -> config.register( - BuildTypeProperty.INSTANCE, - CargoDependenciesProperty.INSTANCE, - CargoFeaturesProperty.INSTANCE, - ExportDependencyGraphProperty.INSTANCE, - ExternalRuntimePathProperty.INSTANCE, - RustIncludeProperty.INSTANCE, - KeepaliveProperty.INSTANCE, - RuntimeVersionProperty.INSTANCE, - SingleFileProjectProperty.INSTANCE, - SingleThreadedProperty.INSTANCE, - WorkersProperty.INSTANCE); - case TS -> config.register( - CoordinationOptionsProperty.INSTANCE, - CoordinationProperty.INSTANCE, - DockerProperty.INSTANCE, - KeepaliveProperty.INSTANCE, - ProtobufsProperty.INSTANCE, - RuntimeVersionProperty.INSTANCE); + case C, CCPP -> + config.register( + AuthProperty.INSTANCE, + BuildCommandsProperty.INSTANCE, + BuildTypeProperty.INSTANCE, + ClockSyncModeProperty.INSTANCE, + ClockSyncOptionsProperty.INSTANCE, + CmakeIncludeProperty.INSTANCE, + CompileDefinitionsProperty.INSTANCE, + CompilerProperty.INSTANCE, + CoordinationOptionsProperty.INSTANCE, + CoordinationProperty.INSTANCE, + DockerProperty.INSTANCE, + FilesProperty.INSTANCE, + KeepaliveProperty.INSTANCE, + NoSourceMappingProperty.INSTANCE, + PlatformProperty.INSTANCE, + ProtobufsProperty.INSTANCE, + SchedulerProperty.INSTANCE, + SingleThreadedProperty.INSTANCE, + TracingProperty.INSTANCE, + TracePluginProperty.INSTANCE, + VerifyProperty.INSTANCE, + WorkersProperty.INSTANCE); + case CPP -> + config.register( + BuildTypeProperty.INSTANCE, + CmakeIncludeProperty.INSTANCE, + CompilerProperty.INSTANCE, + ExportDependencyGraphProperty.INSTANCE, + ExportToYamlProperty.INSTANCE, + ExternalRuntimePathProperty.INSTANCE, + NoRuntimeValidationProperty.INSTANCE, + PrintStatisticsProperty.INSTANCE, + Ros2DependenciesProperty.INSTANCE, + Ros2Property.INSTANCE, + RuntimeVersionProperty.INSTANCE, + TracingProperty.INSTANCE, + WorkersProperty.INSTANCE); + case Python -> + config.register( + AuthProperty.INSTANCE, + BuildCommandsProperty.INSTANCE, + BuildTypeProperty.INSTANCE, + ClockSyncModeProperty.INSTANCE, + ClockSyncOptionsProperty.INSTANCE, + CompileDefinitionsProperty.INSTANCE, + CoordinationOptionsProperty.INSTANCE, + CoordinationProperty.INSTANCE, + DockerProperty.INSTANCE, + FilesProperty.INSTANCE, + KeepaliveProperty.INSTANCE, + NoSourceMappingProperty.INSTANCE, + ProtobufsProperty.INSTANCE, + SchedulerProperty.INSTANCE, + SingleThreadedProperty.INSTANCE, + TracingProperty.INSTANCE, + TracePluginProperty.INSTANCE, + WorkersProperty.INSTANCE); + case Rust -> + config.register( + BuildTypeProperty.INSTANCE, + CargoDependenciesProperty.INSTANCE, + CargoFeaturesProperty.INSTANCE, + ExportDependencyGraphProperty.INSTANCE, + ExternalRuntimePathProperty.INSTANCE, + RustIncludeProperty.INSTANCE, + KeepaliveProperty.INSTANCE, + RuntimeVersionProperty.INSTANCE, + SingleFileProjectProperty.INSTANCE, + SingleThreadedProperty.INSTANCE, + WorkersProperty.INSTANCE); + case TS -> + config.register( + CoordinationOptionsProperty.INSTANCE, + CoordinationProperty.INSTANCE, + DockerProperty.INSTANCE, + KeepaliveProperty.INSTANCE, + ProtobufsProperty.INSTANCE, + RuntimeVersionProperty.INSTANCE); } } } diff --git a/core/src/main/java/org/lflang/target/property/ClockSyncOptionsProperty.java b/core/src/main/java/org/lflang/target/property/ClockSyncOptionsProperty.java index fc24495ad2..d2e1ad83c4 100644 --- a/core/src/main/java/org/lflang/target/property/ClockSyncOptionsProperty.java +++ b/core/src/main/java/org/lflang/target/property/ClockSyncOptionsProperty.java @@ -40,8 +40,8 @@ public ClockSyncOptions fromAst(Element node, MessageReporter reporter) { switch (option) { case ATTENUATION -> options.attenuation = ASTUtils.toInteger(entry.getValue()); case COLLECT_STATS -> options.collectStats = ASTUtils.toBoolean(entry.getValue()); - case LOCAL_FEDERATES_ON -> options.localFederatesOn = - ASTUtils.toBoolean(entry.getValue()); + case LOCAL_FEDERATES_ON -> + options.localFederatesOn = ASTUtils.toBoolean(entry.getValue()); case PERIOD -> options.period = ASTUtils.toTimeValue(entry.getValue()); case TEST_OFFSET -> options.testOffset = ASTUtils.toTimeValue(entry.getValue()); case TRIALS -> options.trials = ASTUtils.toInteger(entry.getValue()); diff --git a/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java b/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java index a89866a650..81e1ea339d 100644 --- a/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java +++ b/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java @@ -31,6 +31,7 @@ public enum ClockSyncMode { private ClockSyncMode(int value) { this.value = value; } + /** Return the name in lower case. */ @Override public String toString() { diff --git a/core/src/main/java/org/lflang/util/FileUtil.java b/core/src/main/java/org/lflang/util/FileUtil.java index 67b62d9a59..3bc09469f4 100644 --- a/core/src/main/java/org/lflang/util/FileUtil.java +++ b/core/src/main/java/org/lflang/util/FileUtil.java @@ -380,6 +380,7 @@ public static void copyFromFileSystem(Path entry, Path dstDir, boolean contentsO throw new IllegalArgumentException("Source is neither a directory nor a regular file."); } } + /** * Copy a given input stream to a destination file. * diff --git a/core/src/main/java/org/lflang/util/LFCommand.java b/core/src/main/java/org/lflang/util/LFCommand.java index 68a29b89d1..3cc4c6286a 100644 --- a/core/src/main/java/org/lflang/util/LFCommand.java +++ b/core/src/main/java/org/lflang/util/LFCommand.java @@ -56,6 +56,7 @@ public class LFCommand { * forwarded. */ private static final int PERIOD_MILLISECONDS = 200; + /** * The maximum amount of time to wait for the forwarding of output and error streams to finish. */ diff --git a/core/src/main/java/org/lflang/validation/ValidatorMessageReporter.java b/core/src/main/java/org/lflang/validation/ValidatorMessageReporter.java index 36a796c81b..06ea7ac713 100644 --- a/core/src/main/java/org/lflang/validation/ValidatorMessageReporter.java +++ b/core/src/main/java/org/lflang/validation/ValidatorMessageReporter.java @@ -89,12 +89,15 @@ protected void report(Path path, Range range, DiagnosticSeverity severity, Strin protected void reportOnNode( EObject node, EStructuralFeature feature, DiagnosticSeverity severity, String message) { switch (severity) { - case Error -> acceptor.acceptError( - message, node, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - case Warning -> acceptor.acceptWarning( - message, node, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); - case Information, Hint -> acceptor.acceptInfo( - message, node, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); + case Error -> + acceptor.acceptError( + message, node, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); + case Warning -> + acceptor.acceptWarning( + message, node, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); + case Information, Hint -> + acceptor.acceptInfo( + message, node, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); } } } 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 e65aa0548c..032971bed4 100644 --- a/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java +++ b/core/src/test/java/org/lflang/tests/compiler/EquivalenceUnitTests.java @@ -18,33 +18,33 @@ public class EquivalenceUnitTests { public void testSimple() { assertSelfEquivalence( """ - target C + target C - reactor Destination { - input ok: bool - input in: int - state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} - } - """); + reactor Destination { + input ok: bool + input in: int + state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} + } + """); } @Test public void testCodeExprEqItselfModuloIndent() { assertEquivalent( """ - target C - reactor Destination { - state s: tag_t = {= - NEVER_TAG_INITIALIZER - =} - } - """, + target C + reactor Destination { + state s: tag_t = {= + NEVER_TAG_INITIALIZER + =} + } + """, """ - target C - reactor Destination { - state s: tag_t = {= NEVER_TAG_INITIALIZER =} - } - """); + target C + reactor Destination { + state s: tag_t = {= NEVER_TAG_INITIALIZER =} + } + """); } private void assertSelfEquivalence(String input) { 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 69dfe74e07..072c32c106 100644 --- a/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java +++ b/core/src/test/java/org/lflang/tests/compiler/FormattingUnitTests.java @@ -19,78 +19,78 @@ public class FormattingUnitTests { public void testSimple() { assertFormatsTo( """ - target C - reactor Main{ } - """, + target C + reactor Main{ } + """, """ - target C + target C - reactor Main { - } - """); + reactor Main { + } + """); } @Test public void testAssignments() { assertFormatsTo( """ - target C + target C - reactor Destination { - input ok: bool - input in: int - state last_invoked: tag_t= {= NEVER_TAG_INITIALIZER =} - } - """, + reactor Destination { + input ok: bool + input in: int + state last_invoked: tag_t= {= NEVER_TAG_INITIALIZER =} + } + """, """ - target C + target C - reactor Destination { - input ok: bool - input in: int - state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} - } - """); + reactor Destination { + input ok: bool + input in: int + state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} + } + """); } @Test public void testState() { assertFormatsTo( """ - target Python + target Python - reactor Destination { - state one_init: tag_t = {=NEVER_TAG_INITIALIZER=} - state no_init: tag_t - state list_init = [1,2] // comment - } - """, + reactor Destination { + state one_init: tag_t = {=NEVER_TAG_INITIALIZER=} + state no_init: tag_t + state list_init = [1,2] // comment + } + """, """ - target Python + target Python - reactor Destination { - state one_init: tag_t = {= NEVER_TAG_INITIALIZER =} - state no_init: tag_t - state list_init = [1, 2] # comment - } - """); + reactor Destination { + state one_init: tag_t = {= NEVER_TAG_INITIALIZER =} + state no_init: tag_t + state list_init = [1, 2] # comment + } + """); } @Test public void testCppInits() { assertIsFormatted( """ - target Cpp + target Cpp - reactor Destination { - state one_init: tag_t({= NEVER_TAG_INITIALIZER =}) - state no_init: tag_t - state assign: int = 0 - state paren: int(0) - state brace: std::vector{1, 2} - state paren_list: std::vector(1, 2) - } - """); + reactor Destination { + state one_init: tag_t({= NEVER_TAG_INITIALIZER =}) + state no_init: tag_t + state assign: int = 0 + state paren: int(0) + state brace: std::vector{1, 2} + state paren_list: std::vector(1, 2) + } + """); } @Inject LfParsingTestHelper parser; 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 66fb64a896..c4663ff9a6 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java @@ -65,15 +65,15 @@ public void initializedState() throws Exception { Model model = parser.parse( """ - target Cpp; - main reactor Foo { - state a(); - state b:int(3); - state c:int[](1,2,3); - state d(1 sec); - state e(1 sec, 2 sec, 3 sec); - } - """); + target Cpp; + main reactor Foo { + state a(); + state b:int(3); + state c:int[](1,2,3); + state d(1 sec); + state e(1 sec, 2 sec, 3 sec); + } + """); Assertions.assertNotNull(model); Assertions.assertTrue( @@ -96,14 +96,14 @@ public void uninitializedState() throws Exception { Model model = parser.parse( """ - target C; - main reactor Foo { - state a; - state b:int; - state c:int[]; - state d:time; - } - """); + target C; + main reactor Foo { + state a; + state b:int; + state c:int[]; + state d:time; + } + """); Assertions.assertNotNull(model); Assertions.assertTrue( @@ -119,6 +119,7 @@ public void uninitializedState() throws Exception { } }); } + /** * Return a map from strings to instantiations given a model. * @@ -141,17 +142,17 @@ public void initialValue() throws Exception { Model model = parser.parse( """ - target C; - 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) { - b1 = new B(y = z); - b2 = new B(y = -2); - } - """); + target C; + 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) { + b1 = new B(y = z); + b2 = new B(y = -2); + } + """); Assertions.assertNotNull(model); Assertions.assertTrue( diff --git a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java index 182a421e10..d72b5d85f1 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaDependencyAnalysisTest.java @@ -153,19 +153,19 @@ public void cyclicDependency() throws Exception { public void circularInstantiation() throws Exception { String testCase = """ - target C; + target C; - reactor X { - reaction() {= - // - =} - p = new Y(); - } + reactor X { + reaction() {= + // + =} + p = new Y(); + } - reactor Y { - q = new X(); - } - """; + reactor Y { + q = new X(); + } + """; Model model = parser.parse(testCase); Assertions.assertNotNull(model); diff --git a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java index 377e3e7a32..61137012a4 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaParsingTest.java @@ -58,19 +58,19 @@ public void checkForTarget() throws Exception { public void testAttributes() throws Exception { String testCase = """ - target C; - @label("somethign", "else") - @ohio() - @a - @bdebd(a="b") - @bd("abc") - @bd("abc",) - @a(a="a", b="b") - @a(a="a", b="b",) - main reactor { + target C; + @label("somethign", "else") + @ohio() + @a + @bdebd(a="b") + @bd("abc") + @bd("abc",) + @a(a="a", b="b") + @a(a="a", b="b",) + main reactor { - } - """; + } + """; parseWithoutError(testCase); } @@ -78,17 +78,17 @@ public void testAttributes() throws Exception { public void testAttributeContexts() throws Exception { String testCase = """ - target C; - @a - main reactor(@b parm: int) { + target C; + @a + main reactor(@b parm: int) { - @ohio reaction() {==} - @ohio logical action f; - @ohio timer t; - @ohio input q: int; - @ohio output q2: int; - } - """; + @ohio reaction() {==} + @ohio logical action f; + @ohio timer t; + @ohio input q: int; + @ohio output q2: int; + } + """; parseWithoutError(testCase); } @@ -96,12 +96,12 @@ main reactor(@b parm: int) { public void testTokenizeEmptyWidth() throws Exception { String testCase = """ - target C; - main reactor { - state foo: int[]; - state foo: int[ ]; //spaces are allowed - } - """; + target C; + main reactor { + state foo: int[]; + state foo: int[ ]; //spaces are allowed + } + """; parseWithoutError(testCase); } diff --git a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java index 404d948264..64aeeaa749 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaScopingTest.java @@ -120,20 +120,20 @@ public void unresolvedHierarchicalPortReference() throws Exception { Model model = parser.parse( """ - target C; - reactor From { - output y:int; - } - reactor To { - input x:int; - } - - main reactor { - a = new From(); - d = new To(); - a.x -> d.y; - } - """); + target C; + reactor From { + output y:int; + } + reactor To { + input x:int; + } + + main reactor { + a = new From(); + d = new To(); + a.x -> d.y; + } + """); Assertions.assertNotNull(model); Assertions.assertTrue( @@ -155,11 +155,11 @@ public void unresolvedReferenceInTriggerClause() throws Exception { Model model = parser.parse( """ - target C; - main reactor { - reaction(unknown) {==} - } - """); + target C; + main reactor { + reaction(unknown) {==} + } + """); validator.assertError( model, @@ -173,11 +173,11 @@ public void unresolvedReferenceInUseClause() throws Exception { Model model = parser.parse( """ - target C; - main reactor { - reaction() unknown {==} - } - """); + target C; + main reactor { + reaction() unknown {==} + } + """); validator.assertError( model, @@ -191,11 +191,11 @@ public void unresolvedReferenceInEffectsClause() throws Exception { Model model = parser.parse( """ - target C; - main reactor { - reaction() -> unknown {==} - } - """); + target C; + main reactor { + reaction() -> unknown {==} + } + """); validator.assertError( model, 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 5454f44fa3..6132e7d0d1 100644 --- a/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/core/src/test/java/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -139,11 +139,11 @@ timer t(1 nsec, 10 msec) public void tracingOptionsCpp() throws Exception { String testCase = """ - target Cpp{ - tracing: {trace-file-name: "Bar"} - }; - main reactor {} - """; + target Cpp{ + tracing: {trace-file-name: "Bar"} + }; + main reactor {} + """; validator.assertWarning( parseWithoutError(testCase), LfPackage.eINSTANCE.getKeyValuePair(), @@ -156,12 +156,12 @@ public void tracingOptionsCpp() throws Exception { public void duplicateVariable() throws Exception { String testCase = """ - target TypeScript; - main reactor Foo { - logical action bar; - physical action bar; - } - """; + target TypeScript; + main reactor Foo { + logical action bar; + physical action bar; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getAction(), @@ -228,24 +228,24 @@ public void disallowReactorCalledPreamble() throws Exception { public void requireSemicolonIfAmbiguous() throws Exception { String testCase = """ - target C + target C - reactor Foo { - output out: int - input inp: int - reaction(inp) -> out {==} - } + reactor Foo { + output out: int + input inp: int + reaction(inp) -> out {==} + } - main reactor { - f1 = new Foo() - f2 = new Foo() - f3 = new Foo() + main reactor { + f1 = new Foo() + f2 = new Foo() + f3 = new Foo() - reaction increment(f1.out) - f2.out -> f3.inp - } + reaction increment(f1.out) + f2.out -> f3.inp + } - """; + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), @@ -257,16 +257,16 @@ reaction increment(f1.out) public void noSemicolonIfNotAmbiguous() throws Exception { String testCase = """ - target C + target C - main reactor { - timer t(0) + main reactor { + timer t(0) - reaction increment(t) - reaction multiply(t) - } + reaction increment(t) + reaction multiply(t) + } - """; + """; validator.assertNoErrors(parseWithoutError(testCase)); } @@ -275,11 +275,11 @@ reaction multiply(t) public void disallowUnderscoreInputs() throws Exception { String testCase = """ - target TypeScript; - main reactor { - input __bar; - } - """; + target TypeScript; + main reactor { + input __bar; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), @@ -292,9 +292,9 @@ public void disallowUnderscoreInputs() throws Exception { public void disallowMainWithDifferentNameThanFile() throws Exception { String testCase = """ - target C; - main reactor Foo {} - """; + target C; + main reactor Foo {} + """; validator.assertError( parseWithoutError(testCase), @@ -308,11 +308,11 @@ public void disallowMainWithDifferentNameThanFile() throws Exception { public void disallowUnderscoreOutputs() throws Exception { String testCase = """ - target TypeScript; - main reactor Foo { - output __bar; - } - """; + target TypeScript; + main reactor Foo { + output __bar; + } + """; validator.assertError( parseWithoutError(testCase), @@ -327,11 +327,11 @@ public void disallowUnderscoreOutputs() throws Exception { public void disallowUnderscoreActions() throws Exception { String testCase = """ - target TypeScript; - main reactor Foo { - logical action __bar; - } - """; + target TypeScript; + main reactor Foo { + logical action __bar; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getAction(), @@ -345,27 +345,27 @@ public void disallowUnderscoreActions() throws Exception { public void warnAgainstMultipleTypes() throws Exception { String testCase = """ - target C - reactor A { - output request:int - input response:float - } + target C + reactor A { + output request:int + input response:float + } - reactor B { - input request:int - output response:float - } + reactor B { + input request:int + output response:float + } - main reactor { - a1 = new A(); - a2 = new A(); - b1 = new B(); - b2 = new B(); + main reactor { + a1 = new A(); + a2 = new A(); + b1 = new B(); + b2 = new B(); - a1.request, b1.response -> b1.request, a1.response - a2.request, b2.response -> b2.request, a2.response - } - """; + a1.request, b1.response -> b1.request, a1.response + a2.request, b2.response -> b2.request, a2.response + } + """; validator.assertWarning( parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "multiple types"); } @@ -375,11 +375,11 @@ public void warnAgainstMultipleTypes() throws Exception { public void disallowUnderscoreTimers() throws Exception { String testCase = """ - target TypeScript; - main reactor Foo { - timer __bar(0); - } - """; + target TypeScript; + main reactor Foo { + timer __bar(0); + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), @@ -393,10 +393,10 @@ public void disallowUnderscoreTimers() throws Exception { public void disallowUnderscoreParameters() throws Exception { String testCase = """ - target TypeScript; - main reactor Foo(__bar) { - } - """; + target TypeScript; + main reactor Foo(__bar) { + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getParameter(), @@ -410,11 +410,11 @@ main reactor Foo(__bar) { public void disallowUnderscoreStates() throws Exception { String testCase = """ - target TypeScript; - main reactor Foo { - state __bar; - } - """; + target TypeScript; + main reactor Foo { + state __bar; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), @@ -428,10 +428,10 @@ public void disallowUnderscoreStates() throws Exception { public void disallowUnderscoreReactorDef() throws Exception { String testCase = """ - target TypeScript; - reactor __Foo { - } - """; + target TypeScript; + reactor __Foo { + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), @@ -445,13 +445,13 @@ public void disallowUnderscoreReactorDef() throws Exception { public void disallowUnderscoreReactorInstantiation() throws Exception { String testCase = """ - target TypeScript; - reactor Foo { - } - main reactor Bar { - __x = new Foo(); - } - """; + target TypeScript; + reactor Foo { + } + main reactor Bar { + __x = new Foo(); + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), @@ -465,11 +465,11 @@ public void disallowUnderscoreReactorInstantiation() throws Exception { public void disallowParenthesisInitialization(String target) throws Exception { String testCase = """ - target - main reactor { - state foo: int(0) - } - """ + target + main reactor { + state foo: int(0) + } + """ .replace("", target); String error = "The target does not support brace or parenthesis based initialization. Please use the assignment operator '=' instead." @@ -483,11 +483,11 @@ public void disallowParenthesisInitialization(String target) throws Exception { public void disallowBraceInitialization(String target) throws Exception { String testCase = """ - target - main reactor { - state foo: int{0} - } - """ + target + main reactor { + state foo: int{0} + } + """ .replace("", target); String error = "The target does not support brace or parenthesis based initialization. Please use the assignment operator '=' instead." @@ -501,18 +501,18 @@ public void disallowBraceInitialization(String target) throws Exception { public void connectionToEffectPort() throws Exception { String testCase = """ - target C; - reactor Foo { - output out:int; - } - main reactor Bar { - output out:int; - x = new Foo(); - x.out -> out; - reaction(startup) -> out {= - =} - } - """; + target C; + reactor Foo { + output out:int; + } + main reactor Bar { + output out:int; + x = new Foo(); + x.out -> out; + reaction(startup) -> out {= + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), @@ -525,21 +525,21 @@ public void connectionToEffectPort() throws Exception { public void connectionToEffectPort2() throws Exception { String testCase = """ - target C; - reactor Foo { - input inp:int; - output out:int; - } - main reactor { - output out:int; - x = new Foo(); - y = new Foo(); + target C; + reactor Foo { + input inp:int; + output out:int; + } + main reactor { + output out:int; + x = new Foo(); + y = new Foo(); - y.out -> x.inp; - reaction(startup) -> x.inp {= - =} - } - """; + y.out -> x.inp; + reaction(startup) -> x.inp {= + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), @@ -555,20 +555,20 @@ public void connectionToEffectPort2() throws Exception { public void connectionToEffectPort3() throws Exception { String testCase = """ - target C; + target C; - reactor Foo { - input in:int; - } - reactor Bar { - input in:int; - x1 = new Foo(); - x2 = new Foo(); - in -> x1.in; - reaction(startup) -> x2.in {= - =} - } - """; + reactor Foo { + input in:int; + } + reactor Bar { + input in:int; + x1 = new Foo(); + x2 = new Foo(); + in -> x1.in; + reaction(startup) -> x2.in {= + =} + } + """; validator.assertNoErrors(parseWithoutError(testCase)); } @@ -580,20 +580,20 @@ public void connectionToEffectPort3() throws Exception { public void connectionToEffectPort3_5() throws Exception { String testCase = """ - target C; + target C; - reactor Foo { - input in:int; - } - main reactor { - input in:int; - x1 = new Foo(); - x2 = new Foo(); - in -> x1.in; - reaction(startup) -> x2.in {= - =} - } - """; + reactor Foo { + input in:int; + } + main reactor { + input in:int; + x1 = new Foo(); + x2 = new Foo(); + in -> x1.in; + reaction(startup) -> x2.in {= + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getVariable(), @@ -609,19 +609,19 @@ public void connectionToEffectPort3_5() throws Exception { public void connectionToEffectPort4() throws Exception { String testCase = """ - target C; + target C; - reactor Foo { - input in:int; - } - main reactor { - input in:int; - x1 = new Foo(); - in -> x1.in; - reaction(startup) -> x1.in {= - =} - } - """; + reactor Foo { + input in:int; + } + main reactor { + input in:int; + x1 = new Foo(); + in -> x1.in; + reaction(startup) -> x1.in {= + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), @@ -634,21 +634,21 @@ public void connectionToEffectPort4() throws Exception { public void multipleConnectionsToInputTest() throws Exception { String testCase = """ - target C; - reactor Source { - output out:int; - } - reactor Sink { - input in:int; - } - main reactor { - input in:int; - src = new Source(); - sink = new Sink(); - in -> sink.in; - src.out -> sink.in; - } - """; + target C; + reactor Source { + output out:int; + } + reactor Sink { + input in:int; + } + main reactor { + input in:int; + src = new Source(); + sink = new Sink(); + in -> sink.in; + src.out -> sink.in; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), @@ -661,11 +661,11 @@ public void multipleConnectionsToInputTest() throws Exception { public void detectInstantiationCycle() throws Exception { String testCase = """ - target C; - reactor Contained { - x = new Contained(); - } - """; + target C; + reactor Contained { + x = new Contained(); + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), @@ -678,14 +678,14 @@ public void detectInstantiationCycle() throws Exception { public void detectInstantiationCycle2() throws Exception { String testCase = """ - target C; - reactor Intermediate { - x = new Contained(); - } - reactor Contained { - x = new Intermediate(); - } - """; + target C; + reactor Intermediate { + x = new Contained(); + } + reactor Contained { + x = new Intermediate(); + } + """; Model model = parseWithoutError(testCase); validator.assertError( @@ -706,22 +706,22 @@ public void detectCausalityLoop() throws Exception { String testCase = """ - target C; + target C; - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } + reactor X { + input x:int; + output y:int; + reaction(x) -> y {= + =} + } - main reactor { - a = new X() - b = new X() - a.y -> b.x - b.y -> a.x - } - """; + main reactor { + a = new X() + b = new X() + a.y -> b.x + b.y -> a.x + } + """; Model model = parseWithoutError(testCase); validator.assertError( model, @@ -740,22 +740,22 @@ public void detectCausalityLoop() throws Exception { public void afterBreaksCycle() throws Exception { String testCase = """ - target C + target C - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } + reactor X { + input x:int; + output y:int; + reaction(x) -> y {= + =} + } - main reactor { - a = new X() - b = new X() - a.y -> b.x after 5 msec - b.y -> a.x - } - """; + main reactor { + a = new X() + b = new X() + a.y -> b.x after 5 msec + b.y -> a.x + } + """; validator.assertNoErrors(parseWithoutError(testCase)); } @@ -765,22 +765,22 @@ public void afterBreaksCycle() throws Exception { public void afterBreaksCycle2() throws Exception { String testCase = """ - target C + target C - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } + reactor X { + input x:int; + output y:int; + reaction(x) -> y {= + =} + } - main reactor { - a = new X() - b = new X() - a.y -> b.x after 0 sec - b.y -> a.x - } - """; + main reactor { + a = new X() + b = new X() + a.y -> b.x after 0 sec + b.y -> a.x + } + """; validator.assertNoErrors(parseWithoutError(testCase)); } @@ -789,22 +789,22 @@ public void afterBreaksCycle2() throws Exception { public void afterBreaksCycle3() throws Exception { String testCase = """ - target C + target C - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } + reactor X { + input x:int; + output y:int; + reaction(x) -> y {= + =} + } - main reactor { - a = new X() - b = new X() - a.y -> b.x after 0 - b.y -> a.x - } - """; + main reactor { + a = new X() + b = new X() + a.y -> b.x after 0 + b.y -> a.x + } + """; validator.assertNoErrors(parseWithoutError(testCase)); } @@ -813,21 +813,21 @@ public void afterBreaksCycle3() throws Exception { public void nonzeroAfterMustHaveUnits() throws Exception { String testCase = """ - target C + target C - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } + reactor X { + input x:int; + output y:int; + reaction(x) -> y {= + =} + } - main reactor { - a = new X() - b = new X() - a.y -> b.x after 1 - } - """; + main reactor { + a = new X() + b = new X() + a.y -> b.x after 1 + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), @@ -840,14 +840,14 @@ public void nonzeroAfterMustHaveUnits() throws Exception { public void nonZeroTimeValueWithoutUnits() throws Exception { String testCase = """ - target C; - main reactor { - timer t(42, 1 sec); - reaction(t) {= - printf("Hello World.\\n"); - =} - } - """; + target C; + main reactor { + timer t(42, 1 sec); + reaction(t) {= + printf("Hello World.\\n"); + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); } @@ -857,14 +857,14 @@ public void nonZeroTimeValueWithoutUnits() throws Exception { public void parameterTypeMismatch() throws Exception { String testCase = """ - target C; - main reactor (p:int = 0) { - timer t(p, 1 sec); - reaction(t) {= - printf("Hello World.\\n"); - =} - } - """; + target C; + main reactor (p:int = 0) { + timer t(p, 1 sec); + reaction(t) {= + printf("Hello World.\\n"); + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), @@ -877,14 +877,14 @@ main reactor (p:int = 0) { public void targetCodeInTimeArgument() throws Exception { String testCase = """ - target C; - main reactor { - timer t({=foo()=}, 1 sec); - reaction(t) {= - printf("Hello World.\\n"); - =} - } - """; + target C; + main reactor { + timer t({=foo()=}, 1 sec); + reaction(t) {= + printf("Hello World.\\n"); + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Invalid time value."); } @@ -894,15 +894,15 @@ public void targetCodeInTimeArgument() throws Exception { public void overflowingDeadlineC() throws Exception { String testCase = """ - target C; - main reactor { - timer t; - reaction(t) {= - printf("Hello World.\\n"); - =} deadline (40 hours) {= - =} - } - """; + target C; + main reactor { + timer t; + reaction(t) {= + printf("Hello World.\\n"); + =} deadline (40 hours) {= + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getDeadline(), @@ -915,15 +915,15 @@ public void overflowingDeadlineC() throws Exception { public void overflowingParameterC() throws Exception { String testCase = """ - target C; - main reactor(d:time = 40 hours) { - timer t; - reaction(t) {= - printf("Hello World.\\n"); - =} deadline (d) {= - =} - } - """; + target C; + main reactor(d:time = 40 hours) { + timer t; + reaction(t) {= + printf("Hello World.\\n"); + =} deadline (d) {= + =} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getParameter(), @@ -938,18 +938,18 @@ main reactor(d:time = 40 hours) { public void overflowingAssignmentC() throws Exception { String testCase = """ - target C; - reactor Print(d:time(39 hours)) { - timer t; - reaction(t) {= - printf("Hello World.\\n"); - =} deadline (d) {= - =} - } - main reactor { - p = new Print(d=40 hours); - } - """; + target C; + reactor Print(d:time(39 hours)) { + timer t; + reaction(t) {= + printf("Hello World.\\n"); + =} deadline (d) {= + =} + } + main reactor { + p = new Print(d=40 hours); + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getAssignment(), @@ -964,13 +964,13 @@ reactor Print(d:time(39 hours)) { public void missingTrigger() throws Exception { String testCase = """ - target C; - reactor X { - reaction() {= - // - =} - } - """; + target C; + reactor X { + reaction() {= + // + =} + } + """; validator.assertWarning( parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), @@ -986,30 +986,30 @@ public void testPreambleVisibility() throws Exception { Model model_reactor_scope = parseWithoutError( """ - target %s; - reactor Foo { - %spreamble {==} - } - """ + target %s; + reactor Foo { + %spreamble {==} + } + """ .formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); Model model_file_scope = parseWithoutError( """ - target %s; - %spreamble {==} - reactor Foo { - } - """ + target %s; + %spreamble {==} + reactor Foo { + } + """ .formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); Model model_no_preamble = parseWithoutError( """ - target %s; - reactor Foo { - } - """ + target %s; + reactor Foo { + } + """ .formatted(target)); validator.assertNoIssues(model_no_preamble); @@ -1061,10 +1061,10 @@ public void testInheritanceSupport() throws Exception { Model model = parseWithoutError( """ - target %s - reactor A{} - reactor B extends A{} - """ + target %s + reactor A{} + reactor B extends A{} + """ .formatted(target)); if (target.supportsInheritance()) { @@ -1085,12 +1085,12 @@ public void testFederationSupport() throws Exception { Model model = parseWithoutError( """ - target %s - reactor Foo {} - federated reactor { - foo = new Foo() - } - """ + target %s + reactor Foo {} + federated reactor { + foo = new Foo() + } + """ .formatted(target)); if (target.supportsFederated()) { @@ -1110,21 +1110,21 @@ public void testFederationSupport() throws Exception { public void stateAndParameterDeclarationsInC() throws Exception { String testCase = """ - target C; - 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 time - y:int = t // ERROR: init using parameter - ) { - state offset:time = 42; // ERROR: units missing - state w:time = x; // ERROR: parameter is not a time - state foo:time = "bla"; // ERROR: assigned value not a time; - timer tick(1); // ERROR: not a time - } - """; + target C; + 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 time + y:int = t // ERROR: init using parameter + ) { + state offset:time = 42; // ERROR: units missing + state w:time = x; // ERROR: parameter is not a time + state foo:time = "bla"; // ERROR: assigned value not a time; + timer tick(1); // ERROR: not a time + } + """; Model model = parseWithoutError(testCase); @@ -1163,12 +1163,12 @@ public void recognizeIPV4() throws Exception { String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """ .formatted(addr, addr); parseWithoutError(testCase); } @@ -1177,12 +1177,12 @@ public void recognizeIPV4() throws Exception { for (String addr : parseError) { String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """ .formatted(addr, addr); parseWithError(testCase); } @@ -1192,12 +1192,12 @@ public void recognizeIPV4() throws Exception { Model model = parseWithoutError( """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """ .formatted(addr, addr)); validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); } @@ -1268,12 +1268,12 @@ public void recognizeIPV6() throws Exception { for (String addr : correct) { String testCase = """ - target C; - reactor Y {} - federated reactor at [foo@%s]:4242 { - y = new Y() at [%s]:2424; - } - """ + target C; + reactor Y {} + federated reactor at [foo@%s]:4242 { + y = new Y() at [%s]:2424; + } + """ .formatted(addr, addr); Model model = parseWithoutError(testCase); validator.assertNoIssues(model); @@ -1283,12 +1283,12 @@ public void recognizeIPV6() throws Exception { for (String addr : parseError) { String testCase = """ - target C; - reactor Y {} - federated reactor X at [foo@%s]:4242 { - y = new Y() at [%s]:2424; - } - """ + target C; + reactor Y {} + federated reactor X at [foo@%s]:4242 { + y = new Y() at [%s]:2424; + } + """ .formatted(addr, addr); parseWithError(testCase); } @@ -1297,12 +1297,12 @@ public void recognizeIPV6() throws Exception { for (String addr : validationError) { String testCase = """ - target C; - reactor Y {} - federated reactor X at [foo@%s]:4242 { - y = new Y() at [%s]:2424; - } - """ + target C; + reactor Y {} + federated reactor X at [foo@%s]:4242 { + y = new Y() at [%s]:2424; + } + """ .formatted(addr, addr); Model model = parseWithoutError(testCase); validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); @@ -1323,12 +1323,12 @@ public void recognizeHostNames() throws Exception { for (String addr : correct) { String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """ .formatted(addr, addr); parseWithoutError(testCase); } @@ -1337,12 +1337,12 @@ public void recognizeHostNames() throws Exception { for (String addr : parseError) { String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """ .formatted(addr, addr); parseWithError(testCase); } @@ -1351,12 +1351,12 @@ public void recognizeHostNames() throws Exception { for (String addr : validationError) { String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """ + target C; + reactor Y {} + federated reactor X at foo@%s:4242 { + y = new Y() at %s:2424; + } + """ .formatted(addr, addr); Model model = parseWithoutError(testCase); validator.assertWarning( @@ -1590,12 +1590,12 @@ private List synthesizeExamples(TargetPropertyType type, boolean correct private Model createModel(Target target, TargetProperty property, String value) throws Exception { return parseWithoutError( """ - target %s {%s: %s}; - reactor Y {} - main reactor { - y = new Y() - } - """ + target %s {%s: %s}; + reactor Y {} + main reactor { + y = new Y() + } + """ .formatted(target, property.name(), value)); } @@ -1841,11 +1841,11 @@ public void testUnusedImport() throws Exception { public void testMissingInputType() throws Exception { String testCase = """ - target C; - main reactor { - input i; - } - """; + target C; + main reactor { + input i; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), @@ -1857,11 +1857,11 @@ public void testMissingInputType() throws Exception { public void testMissingOutputType() throws Exception { String testCase = """ - target C; - main reactor { - output i; - } - """; + target C; + main reactor { + output i; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), @@ -1873,11 +1873,11 @@ public void testMissingOutputType() throws Exception { public void testMissingStateType() throws Exception { String testCase = """ - target C; - main reactor { - state i; - } - """; + target C; + main reactor { + state i; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), @@ -1889,11 +1889,11 @@ public void testMissingStateType() throws Exception { public void testCppMutableInput() throws Exception { String testCase = """ - target Cpp; - main reactor { - mutable input i:int; - } - """; + target Cpp; + main reactor { + mutable input i:int; + } + """; validator.assertWarning( parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), @@ -1906,11 +1906,11 @@ public void testCppMutableInput() throws Exception { public void testOverflowingSTP() throws Exception { String testCase = """ - target C; - main reactor { - reaction(startup) {==} STP(2147483648) {==} - } - """; + target C; + main reactor { + reaction(startup) {==} STP(2147483648) {==} + } + """; // TODO: Uncomment and fix failing test. See issue #903 on Github. // validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getSTP(), null, @@ -1921,11 +1921,11 @@ public void testOverflowingSTP() throws Exception { public void testOverflowingDeadline() throws Exception { String testCase = """ - target C; - main reactor { - reaction(startup) {==} STP(2147483648) {==} - } - """; + target C; + main reactor { + reaction(startup) {==} STP(2147483648) {==} + } + """; // TODO: Uncomment and fix failing test. See issue #903 on Github. // validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getDeadline(), null, @@ -1936,9 +1936,9 @@ public void testOverflowingDeadline() throws Exception { public void testInvalidTargetParam() throws Exception { String testCase = """ - target C { foobarbaz: true } - main reactor {} - """; + target C { foobarbaz: true } + main reactor {} + """; var model = parseWithoutError(testCase); List issues = validator.validate(model); Assertions.assertTrue(issues.size() == 2); @@ -1953,9 +1953,9 @@ public void testInvalidTargetParam() throws Exception { public void testTargetParamNotSupportedForTarget() throws Exception { String testCase = """ - target Python { cargo-features: "" } - main reactor {} - """; + target Python { cargo-features: "" } + main reactor {} + """; var model = parseWithoutError(testCase); List issues = validator.validate(model); Assertions.assertTrue(issues.size() == 2); @@ -1968,10 +1968,11 @@ public void testTargetParamNotSupportedForTarget() throws Exception { @Test public void testUnnamedReactor() throws Exception { - String testCase = """ - target C; - reactor {} - """; + String testCase = + """ + target C; + reactor {} + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), @@ -1983,11 +1984,11 @@ public void testUnnamedReactor() throws Exception { public void testMainHasInput() throws Exception { String testCase = """ - target C; - main reactor { - input x:int; - } - """; + target C; + main reactor { + input x:int; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), @@ -2000,11 +2001,11 @@ public void testFederatedHasInput() throws Exception { String testCase = """ - target C; - federated reactor { - input x:int; - } - """; + target C; + federated reactor { + input x:int; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), @@ -2017,11 +2018,11 @@ public void testMainHasOutput() throws Exception { String testCase = """ - target C; - main reactor { - output x:int; - } - """; + target C; + main reactor { + output x:int; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), @@ -2034,11 +2035,11 @@ public void testFederatedHasOutput() throws Exception { String testCase = """ - target C; - federated reactor { - output x:int; - } - """; + target C; + federated reactor { + output x:int; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), @@ -2051,10 +2052,10 @@ public void testMultipleMainReactor() throws Exception { String testCase = """ - target C; - main reactor A {} - main reactor A {} - """; + target C; + main reactor A {} + main reactor A {} + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), @@ -2067,10 +2068,10 @@ public void testMultipleMainReactorUnnamed() throws Exception { String testCase = """ - target C; - main reactor {} - main reactor {} - """; + target C; + main reactor {} + main reactor {} + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), @@ -2082,10 +2083,10 @@ public void testMultipleMainReactorUnnamed() throws Exception { public void testMultipleFederatedReactor() throws Exception { String testCase = """ - target C; - federated reactor A {} - federated reactor A {} - """; + target C; + federated reactor A {} + federated reactor A {} + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), @@ -2098,10 +2099,10 @@ public void testMultipleMainOrFederatedReactor() throws Exception { String testCase = """ - target C; - federated reactor A {} - federated reactor A {} - """; + target C; + federated reactor A {} + federated reactor A {} + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), @@ -2113,9 +2114,9 @@ public void testMultipleMainOrFederatedReactor() throws Exception { public void testMainReactorHasHost() throws Exception { String testCase = """ - target C; - main reactor at 127.0.0.1{} - """; + target C; + main reactor at 127.0.0.1{} + """; // TODO: Uncomment and fix test // List issues = validator.validate(parseWithoutError(testCase)); // Assertions.assertTrue(issues.size() == 1 && @@ -2128,9 +2129,9 @@ public void testUnrecognizedTarget() throws Exception { String testCase = """ - target Pjthon; - main reactor {} - """; + target Pjthon; + main reactor {} + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getTargetDecl(), @@ -2142,10 +2143,10 @@ public void testUnrecognizedTarget() throws Exception { public void testWrongStructureForLabelAttribute() throws Exception { String testCase = """ - target C; - @label(name="something") - main reactor { } - """; + target C; + @label(name="something") + main reactor { } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getAttribute(), @@ -2157,10 +2158,10 @@ public void testWrongStructureForLabelAttribute() throws Exception { public void testMissingName() throws Exception { String testCase = """ - target C; - @label("something", "else") - main reactor { } - """; + target C; + @label("something", "else") + main reactor { } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getAttribute(), @@ -2172,10 +2173,10 @@ public void testMissingName() throws Exception { public void testWrongParamType() throws Exception { String testCase = """ - target C; - @label(value=1) - main reactor { } - """; + target C; + @label(value=1) + main reactor { } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getAttribute(), @@ -2187,11 +2188,11 @@ public void testWrongParamType() throws Exception { public void testInitialMode() throws Exception { String testCase = """ - target C; - main reactor { - mode M {} - } - """; + target C; + main reactor { + mode M {} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), @@ -2203,12 +2204,12 @@ public void testInitialMode() throws Exception { public void testInitialModes() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM1 {} - initial mode IM2 {} - } - """; + target C; + main reactor { + initial mode IM1 {} + initial mode IM2 {} + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), @@ -2220,16 +2221,16 @@ public void testInitialModes() throws Exception { public void testModeStateNamespace() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - state s:int; - } - mode M { - state s:int; - } + target C; + main reactor { + initial mode IM { + state s:int; } - """; + mode M { + state s:int; + } + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), @@ -2242,16 +2243,16 @@ public void testModeStateNamespace() throws Exception { public void testModeTimerNamespace() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - timer t; - } - mode M { - timer t; - } + target C; + main reactor { + initial mode IM { + timer t; } - """; + mode M { + timer t; + } + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), @@ -2263,16 +2264,16 @@ public void testModeTimerNamespace() throws Exception { public void testModeActionNamespace() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - logical action a; - } - mode M { - logical action a; - } + target C; + main reactor { + initial mode IM { + logical action a; + } + mode M { + logical action a; } - """; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getAction(), @@ -2284,17 +2285,17 @@ public void testModeActionNamespace() throws Exception { public void testModeInstanceNamespace() throws Exception { String testCase = """ - target C; - reactor R {} - main reactor { - initial mode IM { - r = new R(); - } - mode M { - r = new R(); - } + target C; + reactor R {} + main reactor { + initial mode IM { + r = new R(); } - """; + mode M { + r = new R(); + } + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), @@ -2307,16 +2308,16 @@ public void testModeInstanceNamespace() throws Exception { public void testMissingModeStateReset() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - reaction(startup) -> M {==} - } - mode M { - state s:int(0); - } + target C; + main reactor { + initial mode IM { + reaction(startup) -> M {==} + } + mode M { + state s:int(0); } - """; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getMode(), @@ -2329,19 +2330,19 @@ public void testMissingModeStateReset() throws Exception { public void testMissingModeStateResetInstance() throws Exception { String testCase = """ - target C; - reactor R { - state s:int = 0; + target C; + reactor R { + state s:int = 0; + } + main reactor { + initial mode IM { + reaction(startup) -> M {==} } - main reactor { - initial mode IM { - reaction(startup) -> M {==} - } - mode M { - r = new R(); - } + mode M { + r = new R(); } - """; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getMode(), @@ -2356,13 +2357,13 @@ public void testMissingModeStateResetInstance() throws Exception { public void testModeStateResetWithoutInitialValue() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - reset state s:int; - } + target C; + main reactor { + initial mode IM { + reset state s:int; } - """; + } + """; validator.assertError( parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), @@ -2374,16 +2375,16 @@ public void testModeStateResetWithoutInitialValue() throws Exception { public void testUnspecifiedTransitionType() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - reaction(startup) -> M {==} - } - mode M { - reset state s:int = 0; - } + target C; + main reactor { + initial mode IM { + reaction(startup) -> M {==} } - """; + mode M { + reset state s:int = 0; + } + } + """; validator.assertWarning( parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), @@ -2397,9 +2398,9 @@ public void testUnspecifiedTransitionType() throws Exception { public void testMutuallyExclusiveThreadingParams() throws Exception { String testCase = """ - target C { single-threaded: true, workers: 1 } - main reactor {} - """; + target C { single-threaded: true, workers: 1 } + main reactor {} + """; validator.assertError( parseWithoutError(testCase), diff --git a/core/src/testFixtures/java/org/lflang/tests/TestBase.java b/core/src/testFixtures/java/org/lflang/tests/TestBase.java index fb57ea3691..89ff40e517 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestBase.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestBase.java @@ -571,28 +571,28 @@ public static String stackTraceToString(Throwable t) { /** Bash script that is used to execute docker tests. */ private static final String DOCKER_RUN_SCRIPT = """ - #!/bin/bash + #!/bin/bash - # exit when any command fails - set -e + # exit when any command fails + set -e - docker compose -f "$1" rm -f - docker compose -f "$1" up --build | tee docker_log.txt - docker compose -f "$1" down --rmi local + docker compose -f "$1" rm -f + docker compose -f "$1" up --build | tee docker_log.txt + docker compose -f "$1" down --rmi local - errors=`grep -E "exited with code [1-9]" docker_log.txt | cat` - rm docker_log.txt + errors=`grep -E "exited with code [1-9]" docker_log.txt | cat` + rm docker_log.txt - if [[ $errors ]]; then - echo "====================================================================" - echo "ERROR: One or multiple containers exited with a non-zero exit code." - echo " See the log above for details. The following containers failed:" - echo $errors - exit 1 - fi + if [[ $errors ]]; then + echo "====================================================================" + echo "ERROR: One or multiple containers exited with a non-zero exit code." + echo " See the log above for details. The following containers failed:" + echo $errors + exit 1 + fi - exit 0 - """; + exit 0 + """; /** Path to a bash script containing DOCKER_RUN_SCRIPT. */ private static Path dockerRunScript = null; diff --git a/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java b/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java index f0df742fa8..ab20848871 100644 --- a/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java +++ b/core/src/testFixtures/java/org/lflang/tests/TestRegistry.java @@ -288,6 +288,7 @@ public Set getTests(Target t, TestCategory c) { return this.map.get(t).get(c); } } + /** * Enumeration of test categories, used to map tests to categories. The nearest containing * directory that matches any of the categories will determine the category that the test is diff --git a/gradle.properties b/gradle.properties index f3e6983f72..307b046644 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ version=0.7.3-SNAPSHOT [versions] antlrVersion=4.7.2 fasterxmlVersion=2.12.4 -googleJavaFormatVersion=1.15.0 +googleJavaFormatVersion=1.22.0 jacocoVersion=0.8.7 jsonVersion=20200518 jupiterVersion=5.8.2